title: React Native app crash when returning from camera on Android
body: <p>I have a problem that seems to be pretty common, but I haven't found a solution yet. I'm using <strong>react-navigation</strong>, <strong>react-native-screens</strong> and <strong>react-native-image-picker</strong>. That last plugin allows the app to take photos and load photos from gallery. It works most of the time, but sometimes it crashes after taking a photo and returning to the app. I searched for a solution on their GitHub, and there are many reports of this crash, but not a single fix. This crash was also reported in another library, react-native-image-crop-picker, so it doesn't seem to be a problem with the plugin, but with Android.</p>
  <p>This is what I got from Firebase crash logs:</p>
  <blockquote>
  <ul>
  <li>Unable to start activity ComponentInfo{com.myApp/com.myApp.MainActivity}:
  androidx.fragment.app.Fragment$InstantiationException: Unable to
  instantiate fragment com.swmansion.rnscreens.ScreenStackFragment</li>
  <li>Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment</li>
  <li>Screen fragments should never be restored. Follow instructions from <a href="https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067" rel="noreferrer">https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067</a>
  to properly configure your main activity.</li>
  </ul>
  </blockquote>
  <p>This seems to be related to how Android kills background apps when it needs more memory. That last error has a link to a Github issue. They recommend modifying <strong>MainActivity.java -&gt; onCreate()</strong>, and change <em><strong>super.onCreate(savedInstanceState);</strong></em> to <em><strong>super.onCreate(null);</strong></em>. However, this doesn't fix anything, it just makes the app restart instead of crashing, but I still lose the entire navigation stack, and the photo I just took. Is there any proper fix for this problem?</p>