Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent mobile from going into sleep mode when app is running

I want to prevent Android Mobile from going into sleep mode when my threads are sending HTTP request. as what happened while threads are doing HTTP calls mobiles goes to sleep mode and when user wakes up the phone threads never complete.

User has to restart the app. what to do? please help

like image 601
AZ_ Avatar asked Mar 01 '11 14:03

AZ_


1 Answers

You need a WakeLock. There are different kinds of wake locks so be sure to select the least aggressive one that meets your needs. In particular it sounds like you need a Partial Wake Lock.

Partial Wake Lock - Wake lock that ensures that the CPU is running. The screen might not be on.

Also, make sure you add the permission android.permission.WAKE_LOCK to your manifest. And finally be double sure to Release your lock when you are done.

like image 87
Andrew White Avatar answered Sep 19 '22 13:09

Andrew White