Android Onsaveinstancestate () and its pairing method.

Source: Internet
Author: User

Transferred from: http://blog.chinaunix.net/uid-22985736-id-2977672.html

Onsaveinstancestate () and onrestoreinstancestate () are not part of the activity lifecycle and are invoked only when an activity is accidentally destroyed, such as low memory, The home button is pressed (note: Pressing the back key is the active destruction of an activity, which will not be called). You can also use these two methods to stage some data when you need to change the orientation of the screen.

The following example of Baidu Map application, the use of these two methods, used to save and restore the map view.
@Override
protected void Onsaveinstancestate (Bundle outstate) {
CPoint = Mapview.getmapcenter (); Gets the center point of the current Mapview.
Outstate.putint ("Lat", cpoint.getlatitudee6 ()); Temporary presence in Outstate
Outstate.putint ("Lon", Cpoint.getlongitudee6 ());
Super.onsaveinstancestate (outstate);
}

@Override
protected void Onrestoreinstancestate (Bundle savedinstancestate) {
int lat = savedinstancestate.getint ("lat"); Recovering from saved data
int lon = Savedinstancestate.getint ("Lon");
CPoint = new GeoPoint (lat, lon);
Super.onrestoreinstancestate (savedinstancestate);
}

Android Onsaveinstancestate () and its pairing method.

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.