Skip to content Skip to sidebar Skip to footer

Onnewintent() Will Not Fire Until Phone Is Awake

I have found some interesting behavior and do not know why or how to get around it. The activity is a singletask activity, which means onNewIntent() is for the activity while the a

Solution 1:

However the activity is not created until the phone is awake when it is on the top of the stack.

As far as i know, that's by design. The only way to wake up the phone and keep it awake is by grabbing a wake lock.

http://developer.android.com/reference/android/os/PowerManager.WakeLock.html

The typical pattern is that you receive some intent to wake up your app, like the network state has changed, or whatever. In your receiver, in onHandleIntent(), you grab a wake lock. You start a service to do some work, and the service releases the wake lock after it is done.

In your case, the receiver that sends the intent to your activity can grab a partial wake lock, then your activity can grab a screen wake lock. Keep in mind that as long as you hold the wake lock, the phone cannot sleep ... causing it to use much more battery. Wake locks are very dangerous things for that reason.

Note that you must do the lock hand off. If you don't hold a wake lock when onHandleIntent() returns, the device can go right back to sleep. So it'd be something like,

receiver: acquire partiallock
activity: acquire screen lock
activity: release partiallock

You could also probably just grab the screen lock temporarily, then release it ... the screen would come on, then go off normally according to the display timeout setting.

Post a Comment for "Onnewintent() Will Not Fire Until Phone Is Awake"