androidreact-nativeandroid-activityactivity-stack

React Native : MainActivity geting destroyed when app is put in background, when there is a second actitiy on top of it


Hi guy need some help!

In my react native app, I'm starting a SecondActivity on top of the MainActivity, and when i put app in background from the second activity the MainActivity is getting destroyed and get removed from the Activity stack, so after coming back from background, on some event the SecondActivity is emitting some event to JS (React-Native) side but the MainActitiy is already destroyed so there is no JS on top of it to respond to the event.

  1. So point is why MainActivity getting distoryed and how to stop it from doing so.
  2. And strange part is when I did not start the SecondActivity, and perform the above case, The MainActivity works fine it get Stopped and Resumed back when app is put in forground

Thanks.


Solution

  • You can start the activity with startActivityForResult() for this, it will not close your app first activity.

    It helps me.pls check