It's used when the Activity is forcefully terminated by the OS (ex: when your Activity is in the background and another task needs resources). When this happens, onSaveInstanceState(Bundle outstate)
will be called and it's up to your app to add any state data you want to save in outstate
.
When the user resumes your Activity, onCreate(Bundle savedInstanceState)
gets called and savedInstanceState
will be non-null if your Activity was terminated in a scenario described above. Your app can then grab the data from savedInstanceState
and regenerate your Activity's state to how it was when the user last saw it.
Basically in onCreate
, when savedInstanceState
is null, then it means this is a 'fresh' launch of your Activity. And when it's non-null (if your app saved the data in onSaveInstanceState(...)
, it means the Activity state needs to be recreated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…