开发者

Broadcast Receiver

I know that there are two ways to let your program know about a broadcast receiver. You can either specify in the manifest file or you can dynamically register it in the java files. I know if you put it in the java files then you must unregister it also. My question is if you specify it only in the开发者_开发技巧 manifest file is there anywhere you have to specifically unregister it. Maybe in the manifest file? Maybe in the java file? Or perhaps if declared in manifest file you never have to unregister it.

Thanks


Auwall,

As stated in the Documentation:

Base class for code that will receive intents sent by sendBroadcast(). You can either dynamically register an instance of this class with Context.registerReceiver() or statically publish an implementation through the tag in your AndroidManifest.xml. Note: If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won't receive intents when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack

The note about unregistering the BroadcastReceiver only applies to when you register it programatically in onResume(). You will not need to unregister if you registered it in the AndroidManifest.xml.

Source: http://developer.android.com/reference/android/content/BroadcastReceiver.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜