Adham
Adham

Reputation: 64844

how to start a new activity from anther activity ... in android?

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 ?

Upvotes: 0

Views: 2499

Answers (3)

Litux
Litux

Reputation: 121

Try this:

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

Upvotes: 2

Mark B
Mark B

Reputation: 200446

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

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

Upvotes: 2

alex.zherdev
alex.zherdev

Reputation: 24164

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

Upvotes: 0

Related Questions