react-native icon indicating copy to clipboard operation
react-native copied to clipboard

New activities gets destroyed when app goes to background

Open 0xsilver-bullet opened this issue 2 years ago • 6 comments

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

  1. Create React Native app
  2. Using Android Studio, create new activity
  3. 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.
  4. in react native side, add a button that calls this method to open a new activity
  5. 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

0xsilver-bullet avatar Sep 10 '23 12:09 0xsilver-bullet

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

github-actions[bot] avatar Sep 10 '23 12:09 github-actions[bot]

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar Sep 10 '23 12:09 github-actions[bot]

Facing same issue. Any help?

IshaanKr avatar Oct 11 '23 15:10 IshaanKr

Facing also same issue. It is happening only some specific devices

faker007 avatar Nov 14 '23 08:11 faker007

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.

github-actions[bot] avatar May 13 '24 05:05 github-actions[bot]

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.

github-actions[bot] avatar May 13 '24 05:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 20 '24 05:05 github-actions[bot]