views:

313

answers:

1

Hi all,

I am currently firing an Intent to a Broadcast Receiver which in turns starts an Activity.

Then from the same Service another Intent is fired to a Broadcast Receiver thats in the Activity.

The problem is that the Activity isn't getting the Intent meant for it because it is fired before it is alive and the Broadcast Reciever is registered.

I was wondering is there anyway to make sure an Activity is alive before sending an Intent?

Or any other solution to this?

+1  A: 

Why not start the activity if it is not yet alive?

The general mechanism to start a new activity if its not running— or to bring the activity stack to the front if is already running in the background— is the to use the NEW_TASK_LAUNCH flag in the startActivity() call.

That or simply give the activity a chance to start before firing the Intent.

Alternatively you could try using sendOrderedBroadcast to retrieve data back from the broadcast and then possibly do a retry.

public abstract void sendOrderedBroadcast (Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)
Pierre-Antoine LaFayette
I thought I had this fixed but the issue has arisen again. Has anyone an example of how to use a sendOrderedBroadcast? and get data back?
Donal Rafferty