Question

I have problem when rotating. not wish the OnCreate run again

this is the code ----> Manifest

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/>

----> Manifest

<activity 
    android:name=".actManten"
    android:label="Correctivo"
    android:configChanges="keyboard|keyboardHidden|orientation">
</activity>

----> activity

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}   

help me please

Était-ce utile?

La solution

1 - You could lock the activity in one orientation by adding android:screenOrientation="portrait" (or "landscape") to <activity> in your manifest.

2 - You could tell the system that you meant to handle screen changes for yourself by specifying android:configChanges="screenOrientation" in the <activity> tag. This way the activity will not be recreated, but will receive a callback instead (which you can ignore as it's not useful for you).

Personally I'd go with (2). Of course if locking the app to one of the orientations is fine with you, you can also go with (1).

Depending on the option you've chosen, your activity should be declared like this:

1-

<activity 
    android:name=".actManten"
    android:label="Correctivo"
    android:screenOrientation="portrait"
    android:configChanges="keyboard|keyboardHidden|orientation">
</activity>

2-

<activity 
    android:name=".actManten"
    android:label="Correctivo"
    android:configChanges="keyboard|keyboardHidden|orientation|screenOrientation">
</activity>

A note for Android 3.2+ (API 13) - from this version onwards a screen rotate also causes a screen size change which will refresh the UI. You need to declare "orientation|screenSize" instead of just "orientation". http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

Autres conseils

According to the Android docs for the configChanges attribute:

Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

You should change

android:configChanges="keyboard|keyboardHidden|orientation"

to

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top