jldupont
jldupont

Reputation: 96716

Access the "main activity" from a context passed to a BroadcastReceiver?

How would I get access to the "main" activity from inside a BroadcastReceiver?

public void onReceive(Context context, Intent intent)

UPDATE: I am trying to get a reference to the activity from within the Broadcast Receiver executes.

( Android newbie here... please be gentle :)

Upvotes: 2

Views: 678

Answers (1)

ognian
ognian

Reputation: 11541

"Main" activity can mean lot of things - it can be the currently foreground Activity; the Activity that is launched from the app's icon on the home screen; or an tabbed Activity that holds another Activities as tabs. I presume that by "access" you mean to hold an reference to the Activity object.

In any case, if the Activity is know to have only one meaningful instance constructed at any given moment, you can make it singleton.

Upvotes: 1

Related Questions