Reputation: 907
My application is written with React Native with Redux. It appears as though my MainActivity
is destroyed on back button press. When the app is re-opened from the Task Manager or re-launched from the app menu, the app has lost its previous state, which I would like to avoid or work around.
I have read solutions around overriding the onBackButton()
method with moveTaskToBack(true)
, etc. but I'm not convinced it's the right solution.
Is there a clean / correct way to make sure that my app is restarted with the most recent application state? Perhaps this involves persisting the app state somewhere and restoring it when the application comes into the foreground.
Upvotes: 3
Views: 1173
Reputation: 907
The easiest way around this was to set the launchMode
of MainActivity
to singleTask
in AndroidManifest.xml
. Read more about launch modes in the Android docs.
Upvotes: 1