wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

Android app gets stuck on the launch screen when triggered from a notification on a locked screen and the app is not running in the background. #4675

Closed varungupta85 closed 5 years ago

varungupta85 commented 5 years ago

Issue Description

Android app gets stuck on the launch screen when triggered from a notification on a locked screen and the app is not running in the background.

Steps to Reproduce / Code Snippets / Screenshots

In my setup, it happens when the phone is locked and the app is not running in the background and I tap on a user notification for the app that will basically launch the app.

I have created a detox text to simulate this behaviour. I have created two tests:

  1. Launch the app when device is locked
  2. Launch the app when device in not locked

Below are the tests: P.S. Make sure that the emulator on which the tests will be run has a screen lock set to PIN and the PIN is 1234. I ran the tests on the default Pixel_2_API_26

  1. Launch the app when device is locked

    test('launch app from locked screen', async () => {
    await device.terminateApp();
    await Android.pressKeyCode('26')
    await Android.pressKeyCode('26')
    await device.launchApp();
    await Android.executeShellCommand(`input touchscreen swipe 300 1200 500 0 100`)
    await Android.unlockPhoneByPin('1234')
    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
    });
  2. Launch the app when device in not locked

    test('launch app from unlocked screen', async () => {
    await device.terminateApp();
    await Android.pressKeyCode('26')
    await Android.pressKeyCode('26')
    await Android.executeShellCommand(`input touchscreen swipe 300 1200 500 0 100`)
    await Android.unlockPhoneByPin('1234')
    await device.launchApp();
    await expect(elementByLabel('React Native Navigation!')).toBeVisible();
    });

Below is the code for the method unlockPhoneByPin that I added to AndroidUtils.js

  unlockPhoneByPin: (pin) => {
    exec.execSync(`adb shell input text ${pin} && adb shell input keyevent 66`);
  }

Observe that the first test fails because the app gets stuck on the splash screen.

I did some investigation into the code to find out why it is happening and I found that the Navigation.setRoot method is not executed fully. We have a check to make sure that the current activity is not null before setting the root and the current activity happens to be null in this case.

         private void handle(Runnable task) {
        if (activity() == null || activity().isFinishing()) return;
        UiThread.post(task);
    }

Environment

glocore commented 5 years ago

Any updates on this? @varungupta85 were you able to solve for / workaround this?

I'm building a VoIP app and need to show the app over the lock screen on receiving push notifications. I'm able to show the app when the app is still in the background, no problems there. The screen wakes up and the app is fully interactive.

The problem arises when the app has been killed and the devices is locked. The app does start (as I am able to see logs on my Chrome debugger), but a) the app doesn't show up over the lock screen b) upon unlocking, the app shows up, but is stuck at the splash screen.

These are the flags that are enabled in my MainActivity:

window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
window.clearFlags(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);

In addition to the issue of being stuck on the splash screen, I would also greatly appreciate any guidance on how I can get the app to show over the lock screen when the app has been killed, as I am not a native Android developer.

Edit: I've added more details in this SO question.

varungupta85 commented 5 years ago

@platonish No progress on solution for the problem. I am not sure if you can show a react-native screen when the app is locked or the app is not in foreground. For such cases, we use natively defined Android activities.

@guyca Please share if you have any inputs on this issue.

ShaMan123 commented 5 years ago

+1

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] commented 5 years ago

The issue has been closed for inactivity.

Nitesh-Kanyal commented 3 years ago

+1