2

What I'm trying to do is to close the Activity if the user is changing the orientation in the middle of the use.

I have added to this activity the following line in the manifest -

android:configChanges="orientation"

and I have also overridden onConfigurationChanged:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    finish();
}

But it seems that it doesn't do the trick, so what am I doing wrong here?

4

2 回答 2

2

还要添加keyboardHidden 和screenSize。

android:configChanges="orientation|keyboardHidden|screenSize"

注意:screenSize 仅适用于您的应用程序针对 API 级别 13 或更高级别。

于 2013-11-10T20:00:08.103 回答
0
int a=3;

public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    if(a==3 || a==0)
    { 
      a=0;
    }else
{ finish(); }
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    if(a==3 || a==1)
    { 
      a=0;
    }else
{ finish(); }
}
}
于 2013-11-10T20:22:04.513 回答