The problem (it's not a problem, really - it's designed so) is that
your device goes to sleep to save battery when the user is not
actively using their device.
That means that the main CPU will also power down to some state and
for applications the time stops. What you can do is:
* Use the AlarmManager to schedule an alarm every minute (be warned -
that will drain the battery really fast)
* Hold a WakeLock for the CPU - this way the CPU will not shut down
and you will continue to receive the TIME_TICK events (this will drain
the battery even faster)
If you need to do your work every minute and that for a short time
(only for a few minutes), then I guess using one of these 2 methods
would be acceptable. If you need to do stuff every minute for longer
periods of time, I suggest you get rid of that requirement and
redesign your app :)

Tauno

On Mon, Sep 21, 2009 at 12:04 PM, lili <mw...@126.com> wrote:
>
> I wrote a service and I registered BroadcastReceiver in it. In the
> onReceive () method of BroadcastReceiver catagory,I just wrote
> Intent.ACTION_TIME_TICK.equals(intent.getAction()) to receive the
> systenm time every minute and deal with everything that I should do in
> it every minute.But i found a problem that when the mobile phone
> screen was locked and was completely black,my service seems to be
> sleep and does not work,and when I light up the screen(it is still in
> locked condition),the system will automatically run my service.I do
> not know the reason,I guess if it is because my service is not the
> system-level service?
> When the mobile screen is black,Andraid system will hibernate the
> sevice which is not the system-level service,so if this,I should add
> my service to system service,but I know how to use
> android.permission.ADD_SYSTEM_SERVICE? If you can,please send me a
> example about how to add own service to system-level service.This
> problem has been troubled me for two weeks.Thank you very much and
> hoping for reply asap.
> >
>

--~--~---------~--~----~------------~-------~--~----~
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