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. How to send..?

Hi friends,

              I am new to Android. I have an activity where the user have to
enter his details like name,phone number etc. and there is a submit button
when the user clicks on that button i want to send those details as a SMS to
server and I'l get response as a SMS, I don't know how to do. Any ideas
please.....








Regards,
Abhilash.B

-- 

2. Intent for start default navigator (is present)

Hi at all,

I would like start the default navigator with an start point and a end
point, thus users can sees the route between two points.

It's possibile?

-- 

3. mouse speed

4. Porting Gingerbread: compiling on 32-bit machine

5. OOT: Permisi, nubie baru join

6. Unknown application a large number of SMS messages are being sent. Select "OK" to continue, or "Cancel" to stop sending

7. Vertical attributes don't work in RelativeLayout