I'm working on VOIP application and recently encountered a problem. Some devices are not waking up when screen is locked and app is in background. I've made some tests and found out that:
- If app is closed with back button(task destroyed) then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
- If app wasn't started in a while(task wasn't created yet) then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
- If app was in foreground then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
- If user pressed the HOME button, thus putting the task in background and then screen was locked and startActivity() is called - IT DOESN'T WORK, the screen is off and activity's onCreate is not called
So, I guess it's somehow relevant with home button or the fact that application was in background when screen gets locked. The app calls startActivity() when firebase message received or JNI triggered some callbacks
Here is how I unlock the screen:
if (powerManager != null) {
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "App:wakeuptag");
wakeLock.acquire(1000 * 60);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
And here is how I start the activity:
Intent intent = new Intent(context, VCEngine.appInfo().getActivity(ActivityType.CALL));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIsCallFromBackground.set(!AppUtils.isAppOnForeground());
}
intent.putExtra(
context.getString(R.string.extra_conference_join_or_create),
msg);
intent.putExtra(context.getString(R.string.extra_is_audio_call), isAudioCall);
intent.putExtra("isConference", isConference());
context.startActivity(intent);