Scenario:
I have an activity that is running in foreground.. After a while, screen will auto lock.
Later, I receive a new Intent that requires the screen to be shown again regardless of lock screen..
How should I turn on the screen while this activity is just behind the lock screen (when you press lock button again, you will see the activity)
I only know how to turn on the screen when starting an activity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// make incoming call show on locked screen
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
Now I want to turn on the screen after activity has already been created but been in the background after onStop()..
I tried the following but it does not work:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleCallingIntent(intent);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wl = pm.newWakeLock(
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Incoming Call");
wl.acquire();
mDismissButton.postDelayed(new Runnable() {
@Override
public void run() {
// just to test if screen will be on for 10s
wl.release();
}
}, 10000L);
}