Issue Description
We had to change from using launchMode "singleTask" to "singleTop" because of issues with 3rd party component (active screen with it's own Activity) being automatically cancelled when the user launches our app again from Android Home screen Icon. With the singleTop mode we have to make sure we only have one instance running by having this code in our MainActivity:
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isTaskRoot()) {
finish();
return;
}
}
That mandatory super.onCreate call will however cause issues as it will create new Navigator instance that gets then immediately destroyed when we call finish(). The fix for this is to have the NavigationActivity onCreate also have the "isTaskRoot()" check in place to make sure only task root will create new navigator. Not sure if there are some side effects of this in different launchModes but in this specific use case it solves the problem.
Is it even a valid case to have RNN create multiple NavigationActivities and Navigators?
Steps to Reproduce / Code Snippets / Screenshots
Modify your AndroidManifest.xml to have MainActivity android:launchMode="singleTop".
Run the app on android and launch it with different intents using adb:
adb shell am start -f 0x10000000 -n YOUR.PACKAGE.NAME/.MainActivity
adb shell am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -f 0x10600000 -n YOUR.PACKAGE.NAME/.MainActivity
This should cause multiple instances of the app to open and with the fix in MainActivity onCreate (see on top), that won't happen as it automatically closes all non-root activities. However when we call finish() and the newly created Navigator gets destroyed, something breaks in RNN and at least componentDidAppearListeners break on current active screen.
Environment
- React Native Navigation version: 6.4.0
- React Native version: 0.61.5
- Platform(s) (iOS, Android, or both?): Android
- Device info (Simulator/Device? OS version? Debug/Release?): Pixel 3a, Android emulator, ...
Issue Description
We had to change from using launchMode "singleTask" to "singleTop" because of issues with 3rd party component (active screen with it's own Activity) being automatically cancelled when the user launches our app again from Android Home screen Icon. With the singleTop mode we have to make sure we only have one instance running by having this code in our MainActivity:
That mandatory super.onCreate call will however cause issues as it will create new Navigator instance that gets then immediately destroyed when we call finish(). The fix for this is to have the NavigationActivity onCreate also have the "isTaskRoot()" check in place to make sure only task root will create new navigator. Not sure if there are some side effects of this in different launchModes but in this specific use case it solves the problem.
Is it even a valid case to have RNN create multiple NavigationActivities and Navigators?
Steps to Reproduce / Code Snippets / Screenshots
Modify your AndroidManifest.xml to have MainActivity android:launchMode="singleTop".
Run the app on android and launch it with different intents using adb:
This should cause multiple instances of the app to open and with the fix in MainActivity onCreate (see on top), that won't happen as it automatically closes all non-root activities. However when we call finish() and the newly created Navigator gets destroyed, something breaks in RNN and at least componentDidAppearListeners break on current active screen.
Environment