I have alway used onCreate
method inside my Activity
lifecycle to start or restore from a saved state, but recently found that there is another onCreate method which contains a PersistableBundle
:
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
I only found that it has been added since Android 21.
Could anyone please give a complete information about this method, when it calls and the usage?
From what I've been able to gather, if you set a property on your activity in the manifest like this:
then you can use the
PersistableBundle
to recover data after a system shutdown and restart. In other words, a normal Bundle object will keep a record of yoursavedInstanceState
as long as the application is alive. You can use thePersistableBundle
to save data in the event the system is shutdown.You can also use
persistNever
orpersistRootOnly
instead ofpersistAcrossReboots
.You can find more info on the docs here: https://developer.android.com/reference/android/R.attr.html#persistableMode