andfun-kotlin-dessert-pusher
andfun-kotlin-dessert-pusher copied to clipboard
savedInstanceState always remains null after restart
savedInstanceState
will always remain null after the app is killed. It is not passed on to the bundle.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (savedInstanceState != null) { ... }
}
This bug exists since 5 years and Google has decided not to fix this anymore in 2020:
https://issuetracker.google.com/issues/37020082
As also discussed here on StackOverflow: https://stackoverflow.com/questions/6554317/savedinstancestate-is-always-null
I'm learning Android right now and find that quite a strange decision from Google. I hope there are other ways to persist the data and retrieve it at app start.
Had this bug too, but it disappeared when I launched the app directly on the emulator instead of running it from Android Studio.
I've found an interesting article. In it, two methods to "simulate when the system kills the activity due to memory shortage" are explained, both of which involve the developer option of the device.
One of them I tried out is to set Apps->"Don't keep activities" option on, which kills the activity when it goes background.
The savedInstanceState
worked as instructed.
I could deduct from this and Google's questionable response to the issue that it's obsolete, Android seemed to have change the way it kills the process, in that it doesn't technically kill or something, and if you do manually signal kill to the app now, the savedInstanceState
won't behave as expected since that's not Android system does.
@houmie - Test you app this way:
- Install the app in your emulator or mobile device
- Open AndroidStudio and connect your emulator or device.
- Check if it is showing in your Logcat
- Open app and start using the app (make some desserts)
- Put the app in the background
- Open terminal and hit the same command
- Reopen your app again
It will restart from the same saved state.
@2013alfabravo - thanks for the step 1 hint :)
We are intentionally leaving this thread open. Also, we encourage new learners to use the https://knowledge.udacity.com/ platform to discuss specific issues with our experienced mentors.