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. Huge quert and sorting update of content provider

I'm having the same Disk I/O error problem on SQLite Cursor, trying to loop
through 10,000 records, and getting ugly Exceptions:

23625               dalvikvm  I  Uncaught exception thrown by finalizer
(will be discarded):
23625               dalvikvm  I  Ljava/lang/IllegalStateException;:
Finalizing cursor android.database.sqlite.sqlitecur...@499e7c90 on
LogMessages
                                  that has not been deactivated or closed
23625               dalvikvm  I      at
android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
23625               dalvikvm  I      at dalvik.system.NativeStart.run(Native
Method)
23625         AndroidRuntime  E
android.database.sqlite.SQLiteDiskIOException: disk I/O error
23625         AndroidRuntime  E      at
android.database.sqlite.SQLiteQuery.native_fill_window(Native Method)
23625         AndroidRuntime  E      at
android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:75)
23625         AndroidRuntime  E      at
android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:288)
23625         AndroidRuntime  E      at
android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:269)
23625         AndroidRuntime  E      at
android.database.AbstractCursor.moveToPosition(AbstractCursor.java:171)
23625         AndroidRuntime  E      at
android.database.AbstractCursor.moveToFirst(AbstractCursor.java:248)
23625         AndroidRuntime  E      at
android.database.CursorWrapper.moveToFirst(CursorWrapper.java:86)
23625         AndroidRuntime  E

Exception still exists for 5,000 records, but went away when only 3,000
records in the db table.

Looks like an Android bug to me.

Anyone has a fix or is there already a bug issue reported?





> 

2. Project dependency: reusing code and resources from another Android project

> According to

Which gets you little, since you cannot force the user to install A.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


-- 

3. Motorola Droid On A Fast Boat (camcorder demo)

4. Please Help me find why httpcli ent.execute(httppost)锛沘lways throws IOException

5. building android on eeepc701 problem

6. Please help me find documentation on actions for the manifest file

7. Accessing Droid Moto Corporate Calendar database for my widget