What happens with the registered broadcast receivers after the application is killed?

by Tughi » Thu, 25 Mar 2010 23:06:43 GMT


Sponsored Links
 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?

Thanks

--



What happens with the registered broadcast receivers after the application is killed?

by Mark Murphy » Thu, 25 Mar 2010 23:23:28 GMT


 


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 

--


Sponsored Links


What happens with the registered broadcast receivers after the application is killed?

by Tughi » Fri, 26 Mar 2010 21:21:47 GMT


 I had no idea I could do that with the components declared in the
manifest.

Thanks a lot!






--



What happens with the registered broadcast receivers after the application is killed?

by mmonibi » Fri, 23 Apr 2010 08:03:45 GMT


 What if my receiver is registered for the ACTION_BATTERY_CHANGED
intent?

As stated in the documentation, "You can not receive this through
components declared in manifests, only by explicitly registering for
it with Context.registerReceiver()."

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)

I know that I may be able to use the new battery related broadcasts
that have been added to API level 4, but I'm trying to stick to level
3 to ensure compatibility with all devices.

Thanks!







--



What happens with the registered broadcast receivers after the application is killed?

by mmonibi » Fri, 23 Apr 2010 08:03:58 GMT


 What if my receiver is registered for the ACTION_BATTERY_CHANGED
intent?

As stated in the documentation, "You can not receive this through
components declared in manifests, only by explicitly registering for
it with Context.registerReceiver()."

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)

I know that I may be able to use the new battery related broadcasts
that have been added to API level 4, but I'm trying to stick to level
3 to ensure compatibility with all devices.

Thanks!







--



Other Threads

1. Getting & setting apk configuration in Activity

In Android I would recommend storing these as resources that are different
in the different .apks.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

2. gps calendar

i would like to see a gps calendar where you put in a place to be and
the calendar will tell you when you got to leave to get there on time
from where you are?
--~--~---------~--~----~------------~-------~--~----~

3. General Porting Information

4. Add one butten in a tab

5. i wish to join this group to get help for android x86 porting

6. unable to open an initial console in OMAP 2420

7. Additional Contact Information