简体   繁体   English

如何在Android Studio中将控制权从一个活动转移到另一个活动的片段?

[英]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.

相关问题 Android活动向片段控件转移 - Android activity to a fragment control transfer 如何通过活动将额外数据从一个片段传输到另一个片段 - how to transfer extra data from one fragment to another through activity 如何从一个活动导航到另一个活动到 android 中的特定片段 - How to navigate from one activity to another activity to specific fragment in android Android数据从活动传输到另一个活动的TabLayout片段 - Android data transfer from activity to another activity's tablayout fragment 如何在 Android 中将字符串从 Fragment 传输到 Activity - How to transfer String from Fragment to Activity in Android 如何在android中将多个字符串从一个活动转移到另一个活动 - how to transfer more then one string from one activity to another in android 如何在Android中将数据从一项活动转移到另一项活动? - How do I transfer data from one activity to another in Android? 如何在android中将数据从一个活动传输到另一个活动 - How to transfer data from one activity to another in android 如何将数据从开始于另一个片段的片段传输到活动 - How to transfer a data from fragment which is started another fragment to an activity 如何从一个活动中的片段导航到另一个活动中的片段? - How to navigate from fragment in one activity to fragment in another activity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM