I have two classes:
One is Fragment1
which containts fragment - like this:
public class Tab extends FragmentActivity
the second one is activity
- like this:
public class Wallpaper extends Activity
Now I want to start Activity from Fragment1
how can I do this ?
I want to start Activity from Fragment1 how can I do this ?
You have this
public class Tab extends FragmentActivity
in which case you can use the below unless you are starting activity from fragment class
Intent intent = new Intent(Tab.this,Wallpaper.class);
startActivity(intent);
Use the below in your fragment
Intent intent = new Intent(getActivity(),Wallpaper.class);
getActivtiy().startActivity(intent);
getActivity
Return the Activity this fragment is currently associated with.
http://developer.android.com/guide/components/fragments.html
There is an example in the docs check the same
Intent intent = new Intent(context, Wallpaper.class);
// intent.putExtra(....); // put your data
startActivity(intent);
看到这里: Android:从Fragment调用Activity - Google搜索你的问题标题的第一个结果......
try this
Intent intent = new Intent(getActivity(), mFragmentFavorite.class); startActivity(intent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.