开发者

Android - Make sure activity is alive before firing Intent?

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

Then from the same Service another Intent is fir开发者_StackOverflow社区ed 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?


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜