Keep Android service aware, not awake -
i have service (for detecting incoming , outgoing calls) user can start , stop in application; service can start when device restarted.
now i'm running on situation service not "awake" when device asleep; , when call received service not yet awake handle incoming call.
my question how make service aware of condition without keeping wakelock it?
if wakelock way solve this, should best implementation it?
add in manifest:
<uses-permission android:name="android.permission.wake_lock"/>
now in service:
powermanager powermanager; powermanager.wakelock wakelock; @override public void oncreate() { super.oncreate(); powermanager = (powermanager) getsystemservice(power_service); wakelock = powermanager.newwakelock(powermanager.partial_wake_lock, "notify"); }
now,
@override public int onstartcommand(intent intent, int flags, int startid) { wakelock.acquire(); handleservice(intent); return start_sticky; } @override public void ondestroy() { wakelock.release(); }
Comments
Post a Comment