0

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);
Danil.B
  • 880
  • 1
  • 11
  • 23
  • are you using Service that called By Notification ? – Elsunhoty May 22 '19 at 21:58
  • @Elsunhoty startActivity is called from FirebaseMessagingService in onMessageReceived or from JNI callback – Danil.B May 23 '19 at 04:13
  • @Danil.B Hi Sir, Have you found any solution for it? As I'm facing the same problem. – Muhammad Farhan Jan 16 '20 at 06:13
  • @MuhammadFarhan what device are you using? – Danil.B Jan 18 '20 at 02:03
  • @Danil.B On Huawei y7 prime and Samsung s10 – Muhammad Farhan Jan 18 '20 at 12:10
  • @MuhammadFarhan I've solved this problem on Xiomi Redmi Note 5. There was an additional permission in MIUI required to start activity. See here https://stackoverflow.com/questions/56295901/miui-permission-denied-activity-keyguardlocked . As for your case, it might be that you are using Android 10 which restricts activity start even more. – Danil.B Jan 18 '20 at 17:00
  • @Danil.B Thanks for the reference. I researched the issue and found out That There are many problems with Chinese OS-related Devices because of their Battery Optimizations App. and also I found that in Android 10 they restrict such behavior. [Android 10 Restrcitions](https://developer.android.com/guide/components/activities/background-starts) – Muhammad Farhan Jan 19 '20 at 08:51

0 Answers0