Zeus
Zeus

Reputation: 3357

onConfigurationChanged screen stopped rotating on device. Works on emulator

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

Answers (2)

Zeus
Zeus

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

Fraggle
Fraggle

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.

See this Question.

Upvotes: 0

Related Questions