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. App will not Install/Move to SD Card on HTC Desire HD

Hi Folks:

A user of my app has reported the following:

Phone: HTC Desire HD with Android 2.2 with lots of room on the card.
Android version 2.2
Baseband version: 12.28b.60.140eU_26.03.02.26_M
Kernal version 2.6.32.21-g66cfb7a
ht-ker...@and18-2 #1
Tue Oct 26 15:58:17 CST 2010
Build number: 1.35.762.2 CL277020 release-keys
Software number: 1.35.762.2
Browser version: WebKit 3.1

My App is set up to be installed to the SD Card if possible via my use
of the "preferExternal" setting in the manifest file and is installed
on the SD card for many of my users. However this is the second time
that someone with the HTC Desire has reported that they cannot get my
app to be installed or moved to the SD Card.

Can anyone shed some light on what might be happening here?

Thanks.





-- 

2. flick scrolling

Is there an easy way to do that scrolling where someone moves their
finger really fast across the screen and the scrolling continues a bit
after their finger has lifted?

-- 

3. ArrayIndexOutOfBounds in Thread.getState() ...

4. ADT debugger always stops at ALL exceptions

5. Pengen kenalan dengan anggota id-android@googlegroups.com

6. [WTA] Acer Iconia review

7. ( wta) video chat skype