Tughi wrote: > Hi guys, > I want to optimize the CPU usage in my application. > > Currently my application is configured to always receive the > CONNECTIVITY_CHANGED action to force an update if the previous update > failed because there was no connectivity. > What I don't like about this is that the broadcast receiver gets to be > called too many times although it is not needed. > > I was thinking to register my broadcast receiver only if an update > failed using the Context.registerReceiver(BroadcastReceiver receiver, > IntentFilter filter) method. But I'm not so sure if this is a good > idea. > > I'm concerned that if my application is evicted from memory the > broadcast receiver will be unregistered or lost and my application > will not be notified about the future CONNECTIVITY_CHANGED actions. > > The update is done in a short lived service. So if the update fails, > the service will register the broadcast receiver just before it ends > its execution time. > > Can somebody explain what happens to my broadcast receiver after the > application is evicted from memory?
You will leak memory, as your BroadcastReceiver will keep the component in RAM (even if it was destroyed) until such time as Android terminates the process. You might consider going with a manifest-registered receiver, but enabling and disabling the component as needed via PackageManager. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- 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 To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

