About OnCreate (Bundle savedinstancestate, Persistablebundle persistentstate)

Source: Internet
Author: User



API 21 adds a new attribute to the activity, as long as it is set to persistacrossreboots,activity and has the ability to persist, in addition to a new bundle, which is persistablebundle.



OnCreate (Bundle savedinstancestate, Persistablebundle persistentstate)


Same asonCreate(android.os.Bundle)But called-those activities created with the attributepersistableModeSet topersistAcrossReboots.



The persistence here differs from the traditional meaning of the onsaveinstancestate, Onrestoreinstancestate, and OnCreate methods that are specifically implemented in the activity overload.



 
 
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState)

public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState)

public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState)


The Onsaveinstancestate and Onrestoreinstancestate methods are a way to save the disaster, they are not in the "normal" activity life cycle, only some unexpected anomalies will trigger them, such as the screen to switch, press the home button. After API 21, the Persistablebundle parameter is added, so that these methods have the ability to recover data after the system shutdown restart.



Just set the properties in the activity in manifest:



android:persistableMode="persistAcrossReboots"


You can then use the above three methods directly in the activity.
Also note that the API version is 21 and above.






Reference: http://developer.android.com/reference/android/app/Activity.html



Android Combat 26: Persistablemode and activity persistence



About OnCreate (Bundle savedinstancestate, Persistablebundle persistentstate)



About OnCreate (Bundle savedinstancestate, Persistablebundle persistentstate)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.