0

I am using timer and timer task in my app. I want to cancel the timer task by using .cancel() -> This works fine but few times I want to cancel the running timer task which is in sleep. When I use .cancel(), it doesn't work. Cancelling timer also doesn't wake up current sleeping task. Can someone guide me?

user1810931
  • 638
  • 2
  • 11
  • 33

1 Answers1

0

Because the device is in sleep mode. You've to set this to wake up the device if needed:

    final PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE); 
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
    mWakeLock.acquire();

    new AsyncParsingTask().execute();
Reinherd
  • 5,476
  • 7
  • 51
  • 88