您的位置:首页 > 其它

BroadcastReceiver的register与unregister的timing问题

2016-02-10 15:01 363 查看
http://stackoverflow.com/questions/7887169/android-when-to-register-unregister-broadcast-receivers-created-in-an-activity

onDestroy() is not guaranteed to be called, and you could continue receiving broadcasts for a long time, when the Activity is no longer open.

onDestroy()
并不能保证被调用,所以有这种可能:在
onDestroy()
没有被调用的情况下(此时Activity并不在前台foreground),而你还在接收Broadcast,这可能不是你想要的。

所以,如只想在Activity在前台的时候接收Broadcast,那你就用
onResume() / onPause()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: