简体   繁体   中英

how to launch a fragment of an activity from another activity?

I have one activity 'A' which has many buttons on it to call several corresponding fragments of another activity 'B'.

Activity 'B' contains a navigation drawer where i have created fragments for all the items that we have in the navigation drawer.

So, how do i immediately launch suppose 'fragment 1' ( ie one of the items of the navigation drawer), inside Activity B, when Activity A calls Activity B.

Add an extra to your Intent which defines which Fragment should be loaded.

intent.putExtra("fragment","FragA");

In your onCreate in Activity B:

String fragment = getIntent.getStringExtra("fragment");
// Do something to load correct fragment

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM