react-native
react-native copied to clipboard
New activities gets destroyed when app goes to background
Description
I'm working on a react native app where some features are complicated and need to be implemented on native side. in order to implement the feature I created a native module which has only once method to be called from RN side. this method starts a new activity using react application context. the activity opens normally and feature is working but if user moves the app to background while he's in the new activity and then opens the app again by tapping on app icon, the MainActivity starts (activity which hosts RN). I've also found that my new activity calls onDestoryed when the app opens again which is weird.
`class NewActivityPackage: ReactPackage {
override fun createNativeModules(context: ReactApplicationContext): MutableList<NativeModule> {
val modules = mutableListOf<NativeModule>()
modules.add(PoseCameraModule(context))
return modules
}
override fun createViewManagers(p0: ReactApplicationContext): MutableList<ViewManager<View, ReactShadowNode<*>>> {
return mutableListOf()
}
}`
`class NewActivityModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
private val context = reactApplicationContext
override fun getName():String = "NewActivityModule"
@ReactMethod
fun startPoseDetectionCamera(){
val intent = Intent(context, PoseCameraActivity::class.java)
if(intent.resolveActivity(context.packageManager) != null){
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
}
}
companion object{
const val TAG = "NewActivityModule"
}
}`
in my custom activity I'm extending AppCompatActivity
React Native Version
0.71.8
Output of npx react-native info
System: OS: macOS 13.5.1 CPU: (8) arm64 Apple M1 Memory: 838.88 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node Yarn: Not Found npm: 8.19.4 - ~/.nvm/versions/node/v16.20.1/bin/npm Watchman: 2023.08.14.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.12.1 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10671973 Xcode: 14.2/14C18 - /usr/bin/xcodebuild Languages: Java: 11.0.20 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.2.0 => 18.2.0 react-native: 0.71.8 => 0.71.8 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
- Create React Native app
- Using Android Studio, create new activity
- Create new native module and implement one method that opens a new activity by creating an intent using react application context or the current activity context.
- in react native side, add a button that calls this method to open a new activity
- move the app to background while the new activity is opened, and then tap on the app icon again to open it, in my case it opens the main activity and not my custom activity
Snack, screenshot, or link to a repository
https://github.com/moshfiqrony/react-native-android-native-mergerd-boilerplate
that's not my repo but the exact same code produces the same problem
| :warning: | Newer Version of React Native is Available! |
|---|---|
| :information_source: | You are on a supported minor version, but it looks like there's a newer patch available - 0.71.13. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |
| :warning: | Missing Reproducible Example |
|---|---|
| :information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
Facing same issue. Any help?
Facing also same issue. It is happening only some specific devices
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.