LomaxOnTheRun
LomaxOnTheRun

Reputation: 702

Get the activity which started the current activity

I'm looking for a way to get the activity (A) which started my current activity (B).

So A calls:

Intent intent = new Intent(this, B.class);
startActivity(intent);

I'm looking for some method I can call in B to get A, so something like (in B):

Activity a = someMethodToGetCallingActivity();

Any ideas?

CLOSING EDIT:

As all the comments below say, I'm trying to use Android incorrectly. I was looking to get the instance of the activity A, but since there's no guarantee it exists, I can't. It's not a duplicate of the other question suggested because they were trying to work out which Activity (out of many) fired off the current Activity, not trying to get the instance of a particular Activity. Thanks all :)

Upvotes: 1

Views: 413

Answers (4)

DaniZ
DaniZ

Reputation: 604

You can not get intent of Activity A (previous Activity) yet you can pass the details of intent via bundle to Activity B.

Upvotes: 0

ULHAS PATIL
ULHAS PATIL

Reputation: 872

Why don't you use intent.putExtras... And at next activity(B) just get that intent by getIntent and use get...Extra to get that data?

Upvotes: 0

Fixus
Fixus

Reputation: 4641

There is no way to get intent you came from. You can pass intent nam as param or try to invoke some special method

Upvotes: 0

Lary Ciminera
Lary Ciminera

Reputation: 1270

what about passing the activity A name in the intent data and storing it in Activity B when it start?

Upvotes: 4

Related Questions