I just implemented a orientation change feature - e.g. when the layout changes from portrait to landscape (or vice versa). How can I detect when the orientation change event finished.
The OrientationEventListener
didn't work. How can I get notifications about layout orientation change events?
Create the Instance of
OrientationEventListener
classFor loading the layout in layout-land folder means you have two separate layouts then you have to make
setContentView
inonConfigurationChanged
method.If you have only one layout then no necessary to make setContentView in This method. simply
Override activity's method onConfigurationChanged
use this method
And Do not forget to Add this in your Androidmainfest.xml
like this
Use the onConfigurationChanged method of Activity. See the following code:
You also have to edit the appropriate element in your manifest file to include the android:configChanges Just see the code below:
NOTE: with Android 3.2 (API level 13) or higher, the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher, you must declare android:configChanges="orientation|screenSize" for API level 13 or higher.
Hope this will help you... :)
Just wanted to show you a way to save all your Bundle after onConfigurationChanged:
Create new Bundle just after your class:
Next, after "protected void onCreate" add this:
If you add this all your crated classes into MainActivity will be saved.
But the best way is to add this in your AndroidManifest: