The problem here is, imho, that cell location changes cannot be
detected with a broadcast receiver, but instead we have to use a
listener. A broadcast receiver would just be activated/started when
the cell location has changed.
The listener though has to run all the time to be able to "listen". As
far as I understand, there is no other way as to use a permanent wake
lock to listen to cell changes.
I use the boot completed broadcast receiver to start my listener.
Otherwise I would have to start the app/listener manually after each
boot.

This is the code I use for getting the wake lock:
final PowerManager pm = (PowerManager) context.getSystemService
(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wakeLock.acquire();

I use PARTIAL_WAKE_LOCK because I want the screen to go off, though
the cpu should keep processing my listener.

The problem might be, that I have no "context" object withing the
listener. So I pass the context object from the boot completed
receiver to my listener. Could this be the problem?

br and thanx for your help, ash

On 26 Mai, 01:13, Mark Murphy <mmur...@commonsware.com> wrote:
> aaaa wrote:
> > I'm trying to log the phone's cell movement. So I created a
> > PhoneStateListener that is being called when the CellLocation has been
> > changed. Then it informs a logging service to write that new cell
> > information to a log file.
>
> > This works as long as the screen is on. But when the screen goes off,
> > the logging stops.
>
> Correct.
>
> > The PhoneStateListener gets loaded on boot time
> > public class CellStateListener extends PhoneStateListener {
> >   public void onCellLocationChanged(CellLocation location) {
> >     ...
> >     //this is the logging service which is informed when the cell
> > location changes
> >     listener.onCellChanged(mcc, mnc, lac, cid);
> >     ...
> >   }
> > }
>
> If you are doing this from a BroadcastReceiver, that is fairly evil.
>
> > I tried to use the PowerManager to set a PARTIAL_WAKE_LOCK in my
> > logging service. But this doesn't work.
>
> You may be using the WakeLock incorrectly, then. My guess, from your
> symptoms, is that the device is falling asleep, which is why you are not
> detecting new cell location updates.
>
> Bear in mind, though, that permanently holding a WakeLock, so you can
> find out about cell location updates, will mean the CPU never stops, and
> your users will be inclined to beat you about the head with a tire iron
> due to the vastly reduced battery life.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Development Wiki:http://wiki.andmob.org
--~--~---------~--~----~------------~-------~--~----~
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