Il est possible d'éviter l'appel à onCreate lorsque vous changez de paysage à portrait? [fermé]
-
26-10-2019 - |
Question
Il est possible d'éviter l'appel à onCreate lorsque vous changez de paysage à portrait?
Comment?
Merci
La solution
Absolument possible, AndroidManifest.xml
ajouter cette activité à:
android:configChanges="orientation|keyboardHidden"
vous pouvez lire plus d'informations sur cette astuce sur mon article: http://xjaphx.wordpress.com/2011/09/19/the-less-known-over-screen-orientation/
Autres conseils
Read this article Handling Runtime Changes. Basically there are two options
Let android handle configuration changes - then your activity will be recreated and
onCreate
will be invoked again.Handle it yourself - then your activity won't be destroyed.
Yes it is possible to do this, by adding android:configChanges="orientation"
to your manifest.
However, by choosing this path, you lose much of the great resource management in Android.
If you want to appropriately save and restore state since the activity is recreated without the above manifest change, then you will want to look at onSaveInstanceState () and onRestoreInstanceState ()
add this to manifest of the activity - android:configChanges="orientation"