Answer the question
In order to leave comments, you need to log in
How to start an Activity from a non-Activity class?
Somehow, I didn’t google a sensible answer to this question, that’s why I decided to turn to the Habra community for advice, maybe someone will tell you the correct and concise version.
So there is a class:
public class SlideMenuFragment extends ListFragment {
public Context mContext;<br/>
// .....<br/>
Intent intent = new Intent(mContext, AboutActivity.class);<br/>
mContext.startActivity(intent);
Answer the question
In order to leave comments, you need to log in
ListFragment has a getActivity() method:
final Activity a = getActivity();
Intent intent = new Intent(a, AboutActivity.class);
a.startActivity(intent);
if you edit yours, then you can write like this -
Intent intent = new Intent(this, AboutActivity.class);
mContext.startActivity(intent);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question