I have 3 activities, say A, B and C. How can I identify that Activity C is called from Activity A or activity B.
Asked
Active
Viewed 159 times
2 Answers
4
Put an extra on the Intent
that indicates where it originated from.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
Just to add some code, you could check this answer http://stackoverflow.com/questions/5467922/how-to-find-last-activity-from-which-current-activity-is-opened-in-android – GhostDerfel Oct 08 '14 at 11:59
-
already i am passing bundle through putExtras(). Bundle b = new Bundle(); b.putStringArray("selectedItems", outputStrArr); intent.putExtras(b); startActivity(intent); – P C Oct 08 '14 at 11:59
-
@PC: So? Then add something to the `Bundle` that identifies who is starting Activity C. – CommonsWare Oct 08 '14 at 12:02
-
Bundle contains the String[] of selected items from activity B to activity C. – P C Oct 08 '14 at 12:04
0
Send extras to intent stating which activity has launched it.
Intent intent = new Intent(A.this, C.class);
intent.putExtra("FROMACTIVITY", "A");
startActivity(intent);
or
Intent intent = new Intent(B.this, C.class);
intent.putExtra("FROMACTIVITY", "B");
startActivity(intent);
And in Activity C check the value
Intent intent = getIntent();
intent.getStringExtra("FROMACTIVITY");

Vishal Ramachandran
- 175
- 4