how to start a new activity from anther activity …

2019-06-13 15:41发布

i want to start a new activity from ab activity that (extends from Linearlayout) .. but this code is not right

Intent i = new Intent(SearchResultForm.this, MainActivity.class);
startActivity(i);

... ...

public class SearchResultForm extends LinearLayout{ ...

and i get this error ..

No enclosing instance of the type SearchResultForm is accessible in scope

how can i do it ?

3条回答
我命由我不由天
2楼-- · 2019-06-13 16:02

Just guessing since I can't see the rest of your code, but try:

Intent i = new Intent(this, MainActivity.class);
startActivity(i);
查看更多
何必那么认真
3楼-- · 2019-06-13 16:12

If this code is inside an activity's method, just pass this as the first parameter.

查看更多
Ridiculous、
4楼-- · 2019-06-13 16:15

Try this:

Intent i = new Intent(this, MainActivity.getPackageName());
startActivity(i);
查看更多
登录 后发表回答