I have an app that starts a full screen activity at a given time (based on user settings). I need to wake up the device when this happens so the user can see the activity. I use AlarmManager to schedule these events and it seems to work fine (I didn't notice any missed alarm event), however, on some devices it happens that the screen doesn't turn on. In this case if I manually wake up the device then I can see that my activity is there and it's running it just didn't turned on the screen. I can't reproduce it every time, sometimes it works, sometimes it doesn't. There are some devices that work fine all the time. I can see this problem on different OS versions so it's not specific to an SDK I guess.
An example how I set the AlarmManager:
Intent myIntent = new Intent(context, AlarmActivity.class);
myIntent.putExtras(extras);
PendingIntent pIntent = PendingIntent.getActivity(context, ID, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeInMillis, pIntent);
Here is what I use in onCreate of the AlarmActivity:
PowerManager pm;
WakeLock wakeLock;
WakeLock cpuWake;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
pm = (PowerManager) getSystemService(POWER_SERVICE);
cpuWake = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
cpuWake.acquire();
wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.FULL_WAKE_LOCK, TAG);
if (!wakeLock.isHeld()) {
wakeLock.acquire();
}
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.layout);
//rest of the code
Note: I tried it without PARTIAL_WAKE_LOCK, the result was the same behavior.
Any idea what do I do wrong?
I would appreciate any comment as this problem causes me headache now.
Thank you.