Ken Kinder
Ken Kinder

Reputation: 13140

In Android, how do I reference an instantiated Activity object from another Activity?

Suppose I have two Activity classes in my Android app. Inside Activity B, I know that Activity A exists and is instantiated. What's the proper way to access Activity object A from Activity object B?

Upvotes: 2

Views: 2013

Answers (2)

Andrew White
Andrew White

Reputation: 53496

How can you know Activity A is still around? You can't, the OS handles that and you should not assume to know anything about another activity other than the one that's in the foreground.

If you want to pass data around, use Intents or in some cases, just use static variables.

Upvotes: 2

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43098

You cannot access the activity directly. The only mechanism of passing data between activities is Intent mechanism.

Upvotes: 1

Related Questions