在Activity生命週期中註冊BroadcastReceiver和在配置文件中註冊的區別

Setting up a BroadcastReceiver that gets called unnecessarily can be a drain on system resources. The sample application registers the BroadcastReceiver NetworkReceiver in onCreate(), and it unregisters it inonDestroy(). This is more lightweight than declaring a <receiver> in the manifest. When you declare a<receiver> in the manifest, it can wake up your app at any time, even if you haven't run it for weeks. By registering and unregistering NetworkReceiver within the main activity, you ensure that the app won't be woken up after the user leaves the app. If you do declare a <receiver> in the manifest and you know exactly where you need it, you can use setComponentEnabledSetting() to enable and disable it as appropriate. html

http://developer.android.com/training/basics/network-ops/managing.html#detect-changes
android

相關文章
相關標籤/搜索