<p dir="auto">I wrote my fairly simple flutter app and was testing in debug mode in my device. However when I try to relaunch the app again from recent apps of my device the app restarts, no state is saved for the app(even if I relaunch after few seconds).</p>
<h2 dir="auto">What is instance state, and why it exists</h2>
<p dir="auto">On Android, an <a href="https://developer.android.com/reference/android/app/Activity.html" rel="nofollow">Activity</a> can be killed at any time by the system. This happens usually when Android needs memory when your Activity is not in the foreground, or because of a non-handled configuration change, such as a locale change.<br>
To avoid the user having to restart what he did from scratch when Android killed the Activity, the system calls <code class="notranslate">onSaveInstanceState(…)</code> when the Activity is paused, where the app is supposed to save it's data in a <a href="https://developer.android.com/reference/android/os/Bundle.html" rel="nofollow"><code class="notranslate">Bundle</code></a>, and passes the saved bundle in both <code class="notranslate">onCreate(…)</code> and <code class="notranslate">onRestoreInstanceState(…)</code> when the task is resumed if the activity has been killed by the system.</p>
<h2 dir="auto">The issue about it in flutter</h2>
<p dir="auto">In the flutter apps I tried (Flutter Gallery, and the base project with the FAB tap counter), if I open enough apps to make Android kill the flutter app's Activity, all the state is lost when I come back to the flutter activity (while not having remove the task from recents).</p>
<h2 dir="auto">Steps to Reproduce</h2>
<ol dir="auto">
<li>Install <a href="https://play.google.com/store/apps/details?id=io.flutter.gallery&amp;hl=en" rel="nofollow">Flutter Gallery</a></li>
<li>Open the device's settings, and in developer options, switch "Don't keep activities" on. (see the screenshot)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/638bbb860d55c8bf2e17350342b1165037242d7e361f24e625ea0e0f7318a364/68747470733a2f2f7062732e7477696d672e636f6d2f6d656469612f43773671646866575141414b6f5f4a2e6a70673a736d616c6c"><img src="https://camo.githubusercontent.com/638bbb860d55c8bf2e17350342b1165037242d7e361f24e625ea0e0f7318a364/68747470733a2f2f7062732e7477696d672e636f6d2f6d656469612f43773671646866575141414b6f5f4a2e6a70673a736d616c6c" alt="dev_option" data-canonical-src="https://pbs.twimg.com/media/Cw6qdhfWQAAKo_J.jpg:small" style="max-width: 100%;"></a><br>
This will allow to simulate when Android kills Activities because it lacks memory and you're not in the foreground.</li>
<li>Open the Flutter Gallery app and go anywhere other than the main screen.</li>
<li>Go to the launcher by pressing the device's home button.</li>
<li>Press the overview button and return to Flutter Gallery. Here's the bug.</li>
</ol>
<p dir="auto"><strong>What's expected:</strong> The app is in the same state that where we left off, with untouched UI.<br>
<strong>What happens:</strong> The activity is restarted from scratch, losing all the UI state, even really really long forms.</p>