React-native-navigation: 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.

Created on 1 Feb 2019  路  6Comments  路  Source: wix/react-native-navigation

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();
  });
  1. 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

  • React Native Navigation version: 2.8.0
  • React Native version: 0.57.8
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): Both
馃彋 stale

All 6 comments

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.

@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.

+1

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.

The issue has been closed for inactivity.

+1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

birkir picture birkir  路  3Comments

zagoa picture zagoa  路  3Comments

viper4595 picture viper4595  路  3Comments

switchtrue picture switchtrue  路  3Comments

zhanguangao picture zhanguangao  路  3Comments