How to make activity react to local Broadcasts while paused?

戏子无情 提交于 2019-12-06 03:40:48

What I've done in the past is have my activities register a receiver onResume and unregister onPause.

When you've finished creating your certificates save to local storage whatever information you need to update your view and send out the broadcast.

If the activity is running it will receive the broadcast and update itself. If it it is paused, you should read the local storage onResume and update accordingly.

After all I found a solution that fits my needs. I create a BroadcastReceiver that is used as a subclass of my activity. Whenever the activity enters a paused state, it will call .pause() on my BroadcastReceiver. From that point all incoming Intents are put into a queue and will be flushed on a call to .unpause() from the activity.

Why don't you simply unregister the receiver onDestroy? So while activity is paused, you can still execute code in the receiver?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!