开发者

how do i ensure that a service is running even if the phone is on standby?

I have a service that spawns a thread which runs a task every 3 seconds.

class MyService extends Service {
  private Timer timer = new Timer();

  public int onStartCommand(Intent intent, int flags, int startId) {
    TimerTask task = new TimerTask() {
      public void run() {
        // something important
      }
    };

    timer.scheduleAtFixedRat开发者_开发技巧e(task, 0, 3000);
    return Service.START_STICKY;
  }
  ...
}

My service runs fine when my phone is on, but when my phone is on standby, the service is often not responding.

Any clues as to how I can ensure my service is running while on standby?


Maybe use alarms via AlarmManager class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜