Android activity resumes when orientation changes

I read a lot of posts about this issue, such as [this link] [1], and one solution adds the configChanges orientation to manifest and handle the onConfigurationChanged event to prevent the onCreate operation from repeating during rotation. I did this and the event fires properly, however after that execution the onCreate method also executes! What for? What am I missing? Thanks you

manifest

<activity 
            android:name="webPush"
            android:configChanges="keyboardHidden|orientation"/>

activity,

@Override
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(R.layout.vistaaib);
    }

@Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vistaaib);
...
+5
source share
6 answers

I think it will work .........

<activity android:name=".MyActivity"
          android:configChanges="orientation|keyboardHidden"
          android:label="@string/app_name">

Android 3.2 ( API 13), , . , API 13 ,

android:configChanges="orientation|screenSize"
+11

. , .

<activity
        android:name="?"
        android:label="@string/?"
        android:theme="@style/?" 
        android:configChanges="orientation|screenSize">

, - , .

public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}
+2

.

, . <activity android:name=".YourActivity" android:configChanges="orientation|keyboardHidden"/>

+1

. , - . :

android:configChanges="orientation|keyboard|keyboardHidden"
+1

API 12

.

    android:configChanges="orientation"

.-

    <activity
        android:name=".NameOfYourActivity"
        android:configChanges="orientation"/>

android 3.2 ( API 13) , .

,

    android:configChanges="orientation|screenSize"
0

: screenSize

The current available screen size has changed. This means changing the current available size relative to the current aspect ratio, so it will change when the user switches between landscape and portrait. However, if your application targets API level 12 or lower, your activity always processes this change in the configuration itself (this configuration change does not restart your activity even when running on an Android 3.2 or higher device). Added to API Level 13.

so along with the "orientation" add also "screenSize"

0
source

All Articles