Reputation: 3357
I wanted to stop my activity from refreshing every time the orientation changes. I achieved this by implementing.
@Override 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(); } }
However when I remove the IF code to display the Toast, it stops working. Screen starts refreshing on the device. This works fine on emulator.
Has anyone faced this kind of issue ?
Upvotes: 1
Views: 530
Reputation: 3357
I finally solved this by using
protected void onSaveInstanceState(Bundle outState) {
webView.saveState(outState);
}
http://roman-dotnet.blogspot.com/2011/05/android-webview-orientation-changes.html
Upvotes: 1
Reputation: 8727
Ensure that you are not calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); anywhere. This will cause onConfigurationChange() to not fire.
Put soome log statements in to check to make sure it is firing (and put some log statements in onCreate to check to make sure it is or is not firing during the config change.
Upvotes: 0