3 messages in com.googlegroups.android-developersRe: Persistence of handlers registere...
FromSent OnAttachments
will...@gmail.com30 Mar 2008 02:51 
hackbod30 Mar 2008 20:16 
will...@gmail.com30 Mar 2008 20:36 
Subject:Re: Persistence of handlers registered with Context.registerReceiver
From:hackbod (hack@gmail.com)
Date:03/30/2008 08:16:52 PM
List:com.googlegroups.android-developers

The persistence of registerReceiver() is tied to the context you are calling it on. For an Activity, it is active until the activity's onDestroy() method returns. For a Service, it is likewise active until onDestroy(). For an Application, it is active for the life of the process.

If you are wanting to do stuff in response to SMS messages, though, it seems likely that you will want to be called even if your application is not in for foreground? If so, then you -must- register in the manifest, so the system will know what you are interested in and be able to launch you.

You are right, though, that we don't want to have a bunch of applications launched even when they are not interested in some particular data. To this end, you can use the PackageManager.setComponentEnabledSetting() method to disable your IntentReceiver component when it is not needed:

http://code.google.com/android/reference/android/content/pm/PackageManager.html#setComponentEnabledSetting(android.content.ComponentName,%20int)

On Mar 30, 2:51 am, "will@gmail.com" <will@gmail.com> wrote:

My application responds to various system-wide intents and what it responds to depends on the configuration of the user (e.g. the use can set whethere it should respond to incoming SMS or not, should respond to network tickles or not, etc).

While I could just register all the handlers/receivers using the manifest. I feel that it would be a waste of cycles if every configurable handler gets registered via the manifest and in that handler, will do a check against the preference settings to see whether it should execute or not. So, I thought of assigning the handlers programatticaly instead, simply registering the needed handlers via Context.registerReceiver.

My issue is, the documentation does not state how persistent is the Context.registerReceiver registry. That is, if the device gets rebooted, do I have to re-register the recievers again (i.e. have a service auto-start with the boot sequence which registers the