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?
Asked
Active
Viewed 194 times
1 Answers
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
-
How can the device be in sleep mode? only the thread is in sleep mode in my case, I need to wake that thread up as another thread is ready to run its execution. – user1810931 Oct 17 '13 at 12:24
-
And also I am using timer and timertask – user1810931 Oct 17 '13 at 12:24