On Wed, Jan 5, 2011 at 5:13 PM, Raj <rnmalho...@gmail.com> wrote:
> I am trying to write a simple receiver that will receive the
> BOOT_COMPLETED broadcast, and in turn register a location change
> listener. I know the receiver is transient, and has a short lifespan.
> Once the receiver dies, will my listener still continue to be
> registered, or do I have to write a (perpetual) service to register
> the listener?

Ideally, neither. If all goes well, on Friday I'll be releasing a
LocationPoller service that will handle this scenario, though I don't
recommend trying to get locations already at boot time (wait a couple
of minutes via AlarmManager).

> public class LocationReceiver extends BroadcastReceiver {
>
>       �...@override
>        public void onReceive(Context context, Intent intent) {
>                Log.d("PreciseLocator", "===In Receiver, starting listener");
>                LocationManager lm =
> (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
>                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,
> 500.0f, new DroidLocationListener());
>
>        }
> ......

This will leak the listener, until such time as Android gets rid of or
recycles your process. This is not a good strategy.

> Can I have just a receiver,
> without an activity in the manifest?

Yes, though Android Market users tend to greatly dislike this.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to