Switching from Portrait to Landscape in Android
This is probably a beginner question, but I've already tried looking for an answer and couldn't find one. I was testing an Android app I made on my phone and it was working fine until I switched from portrait to landscape, just to see what would happen. It pretty much made the app go back to the home page, so开发者_如何转开发 I'm guessing it calls onCreate() every time the orientation changes. Is it possible to prevent an orientation change from restarting everything, and just have it switch all the views to fit landscape or portrait mode?
This question has been answered thousand times, but ...
You should add in you Manifest.xml for your activity android:configChange="orientation"
and then override onConfigurationChanged(newConfig)
method and do not add anything inside, since you are telling you app to do nothing when config changes occur.
Whenever the orientation changes onCreate() method gets called again and again. Inorder to prevent that add android:configChanges="orientation|keyboardHidden|screenSize" to the Manifest file, and then override onConfigurationChanged() method.
精彩评论