[英]Call activity from fragment in android
I have two classes: 我有两节课:
One is Fragment1
which containts fragment - like this: 一个是Fragment1
,它包含片段 - 像这样:
public class Tab extends FragmentActivity
the second one is activity
- like this: 第二个是activity
- 像这样:
public class Wallpaper extends Activity
Now I want to start Activity from Fragment1
how can I do this ? 现在我想从Fragment1
启动Activity我该怎么做?
I want to start Activity from Fragment1 how can I do this ? 我想从Fragment1启动Activity我该怎么做?
You have this 你有这个
public class Tab extends FragmentActivity
in which case you can use the below unless you are starting activity from fragment class public class Tab extends FragmentActivity
在这种情况下你可以使用下面的内容,除非你从fragment类开始活动
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. 返回此片段当前与之关联的Activity。
http://developer.android.com/guide/components/fragments.html 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); Intent intent = new Intent(getActivity(),mFragmentFavorite.class); startActivity(intent); startActivity(意向);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.