user590849
user590849

Reputation: 11765

Find out which activity started my activity?

I want to find out which activity started my activity in android. I can get the intent that started the activity using getIntent() but I am not able to find out which activity started the intent in the first place.

Upvotes: 33

Views: 14321

Answers (2)

David Wasser
David Wasser

Reputation: 95568

You can use ActivityCompat.getReferrer() for this purpose.

Upvotes: 11

Reno
Reno

Reputation: 33782

Use getCallingActivity()

Note: if the calling activity is not expecting a result (that is it did not use the startActivityForResult(Intent, int) form that includes a request code), then the calling package will be null

Upvotes: 30

Related Questions