Simran
Simran

Reputation: 633

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' ( i.e one of the items of the navigation drawer), inside Activity B, when Activity A calls Activity B.

Upvotes: 1

Views: 612

Answers (1)

Stefan
Stefan

Reputation: 2178

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

Upvotes: 3

Related Questions