[英]How to transfer control from one activity to fragment of another activity in android studio?
How to transfer control from one activity to fragment of another activity in android studio. 如何在Android Studio中将控制权从一个活动转移到另一个活动的片段。 For example I have activity A and B. Activity B had 2 fragments f1,f2.
例如,我有活动A和活动B。活动B有2个片段f1,f2。 How to transfer control from A to f2?
如何将控制权从A转移到f2?
从第一个活动传递一些意图标志到第二个活动,在第二个活动中使用getIntent()在该标志打开所需片段的帮助下检查标志的类型。
Just add this code in your Activity B in onCreate() 只需将此代码添加到onCreate()中的活动B中
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame, new f2());
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
Now,simply use explicit intent to go to Activity B from Activity A, 现在,只需使用显式意图从活动A转到活动B,
Intent intent=new Intent(ActivityA.this,ActivityB.class);
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.