Hi, Can somebody explain what happens to my broadcast receiver after the > application is evicted from memory? >
If the BroadcastReceiver is dynamically registered by the Service, it will not be leaked if you make sure it is unregistered when the Service is destroyed. After the Service is restarted (after being killed by the system) it will try to update once again. When this update fails you will register the BroadcastReceiver once again to listen for connection changes. >From the Android Service docs: *Note this means that most of the time your service is running, it may be killed by the system if it is under heavy memory pressure. If this happens, the system will later try to restart the service. An important consequence of this is that if you implement onStartCommand()<http://developer.android.com/reference/android/app/Service.html#onStartCommand%28android.content.Intent,%20int,%20int%29>to schedule work to be done asynchronously or in another thread, then you may want to use START_FLAG_REDELIVERY<http://developer.android.com/reference/android/app/Service.html#START_FLAG_REDELIVERY>to have the system re-deliver an Intent for you so that it does not get lost if your service is killed while processing it. * In other words if you bind the lifecycle of the Service to the dynamically registered Service, the BroadcastReceiver will only exist while the Service exists - no leaking. Is there anyway to make sure my receiver is always registered for this > intent, even if the process is destroyed? Would it make a difference > if I used the application context when registering the receiver > instead of the activity context? (frankly, I still don't have a good > grasp of the context object and don't quite understand how the > application and activity contexts differ) > If you want your Application to listen for BroadcastIntents even when it is not running you need to register it statically. But I prefer dynamic registration, otherwise you will always be notified of the changes. You can avoid always being notified by using: http://developer.android.com/training/monitoring-device-state/manifest-receivers.html But if you are only worried that when components of you app are killed you will not receive updates, remember that you can request that the system restart Services after it killed them. Heila -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.

