I read many posts about this problem like [this link][1] and one solution is add orientation configChanges to manifest and handle onConfigurationChanged event in order to prevent onCreate activity to be called again when rotation. I did it and event is triggered properly, however, after this execution, onCreate method is also executed! why? what I am missing? Thank 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);
...
I think this will work.........
<activity android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name">
Beginning with Android 3.2 (API level 13), the will "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 use
android:configChanges="orientation|screenSize"
I Did this. I added This code to manifest and it works perfect.
<activity
android:name="?"
android:label="@string/?"
android:theme="@style/?"
android:configChanges="orientation|screenSize">
You will need to add this under you activity if you want to change something when the device is rotation.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With