android how to start an activity from a FragmentActivity when it implements a ActionBar.TabListener

StackOverflow https://stackoverflow.com/questions/20874544

سؤال

can anybody tell me how should I start an activity from a class like this in Andoird:

public class MyActivity extends FragmentActivity implements ActionBar.TabListener{
      startActivity(new Intent(this, AnotherActivity.class)); //Doesn't work like this     
}
هل كانت مفيدة؟

المحلول 2

Yes, you can. FragmentActivity is a subclass of Activity, which has the "startActivity" public method. You have to call that method from inside of onCreate, for example.

FragmentActivity | Android Developers

Edit: If your fragment is contained in the Activity class (i.e. is an inner class) you can use ActivityClassName.this as the first argument, otherwise, if you need to access your main activity from a Fragment class that has it's own file, you can always use the Fragment's getActivity() method as the first argument.

نصائح أخرى

Change startActivity(new Intent(this, AnotherActivity.class)) to startActivity(new Intent(MyActivity.this, AnotherActivity.class))

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top