title: How do I persist state for android apps killed in the background in react-native
body: <p>When an Android App is sent to the background, it can persist its instance state in case it gets killed due to low memory (see <a href="https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)" rel="noreferrer">Activity:onSaveInstanceState()</a> and the bundle argument for <a href="https://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)" rel="noreferrer">Activity:onCreate(Bundle savedInstanceState)</a>).</p>
  
  <p>The default Activity behaviour is saving the state of the view hierarchy so for a lot of cases you don't have to write any code and it "just works"[tm].</p>
  
  <p>Now for react-native this is not true. React native apps are hosted in a single MainActivity and their state is contained in the javascript interpreter in the app.</p>
  
  <p>I created a sample repository with short documentation how to reproduce my problem here: <a href="https://github.com/einvalentin/react-native-state-test" rel="noreferrer">https://github.com/einvalentin/react-native-state-test</a></p>
  
  <p>I would want react-native to hook into the native android app state serialisation mechanism while providing application developers hooks to extend if they need custom serialisation. Alternatively I could see myself extending the MainActivity to forward the lifecycle events to the Javascript layer and do some custom state serialisation manually there - but this feels a bit clunky.</p>
  
  <p>Is there an obvious way I have overlooked to save the state in react-native so that apps that are killed in the background are not restarted from scratch? This can always happen for example on low memory devices receiving a phone call while interacting with your app.</p>
  
  <p>Thanks a lot!</p>