How to solve the problem of the Android screen switching data loss _android

Source: Internet
Author: User

When the Android screen switches, the current activity is destroyed, and the data on the activity will be lost.
If the checkbox for each item above is ListView, the check box will lose all selected information when the screen is switched.

Solution 1: Add android:configchanges= "Orientation|keyboardhidden" to Androidmanifest.xml's activity tag

<activity 
   android:configchanges= "Orientation|keyboardhidden" 
   android:label= "Sqltest" 
   android: Name= ". SqlData " 
   
  </activity> 

Solution 2: force limit activity in horizontal screen state or vertical screen state, do not allow activity to switch at the same screen
Landscape means horizontal screen
Portrait represents the vertical screen

<activity 
   
   android:label= "sqltest" 
   android:name= ". SqlData " 
   android:screenorientation=" Landscape "> 
  </activity> 

Solution 3: in activity, through replication . onconfigurationchanged method, to achieve the different screen state of the processing mode.

@Override public 
 void onconfigurationchanged (Configuration newconfig) { 
  //TODO auto-generated stub 
  super.onconfigurationchanged (newconfig); 
   * * Horizontal screen detection 
   / 
  if (This.getresources (). GetConfiguration (). Orientation 
 
  = = Configuration.orientation_landscape) { 
 
   //current for horizontal screen 
   //implementation Code 
 
  } 
 
  else if (this.getresources (). GetConfiguration (). Orientation 
 
  = = configuration.orientation_portrait) { 
 
   //current for vertical screen 
   //implementation Code 
 
  } 
   * * Entity keyboard status Detection 
 
  /if (newconfig.hardkeyboardhidden 
 
  = = Configuration.hardkeyboardhidden_ NO) { 
 
   //entity keyboard in Eject State 
   //implementation Code 
 
  } 
 
  else if (newconfig.hardkeyboardhidden 
 
  = = Configuration.hardkeyboardhidden_yes) { 
 
   //entity keyboard is in close State 
   //implementation Code 
 
  } 
 
 

author:conowen@ Big Clock

Original address: Http://blog.csdn.net/conowen

This is the entire content of this article, I hope to learn more about Android software programming help.

Related Article

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.