Android is about the problem of calling a photo or returning to the vertical screen when the horizontal screen page is called, the Activity is destroyed and recreated.

Because the business needs to take pictures, take pictures (and handle compatibility issues) in a transparent Activity

Turn on the activity and directly turn up the camera. Then I found that some models have been repeatedly taking pictures on the horizontal screen. I printed it, and it turned out that the activity was destroyed and recreated because of the horizontal and vertical screen problems.

 Solution one:

                    You can save data

 /**
  * 用于保存状态
  */
 @Override
 protected void onSaveInstanceState(Bundle outState) {
  // TODO Auto-generated method stub
     
  outState.putString("data", "数据");  
    
  super.onSaveInstanceState(outState);
 }
 /**
  * 用于恢复状态
  */
 
 @Override
 protected void onRestoreInstanceState(Bundle savedInstanceState) {

   String data=savedInstanceState.getString("data");
 
 }

Method Two

      Not guaranteed for all models

 <activity android:name=".ui.system.PhotoActivity"
            android:launchMode="singleTask"
            android:configChanges="orientation|screenSize|keyboardHidden"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            >

 

Guess you like

Origin blog.csdn.net/qq_36767261/article/details/81240034