private OrientationEventListener mOrientationListener;
开始
@Override
protected void onResume() {
super.onResume();
// 注册方向回调,检测屏幕方向改变
if (null == mOrientationListener) {
mOrientationListener = new OrientationEventListener(this) {
@Override
public void onOrientationChanged(int orientation) {
//todl
}
};
mOrientationListener.enable();
}
}
停止
@Override
protected void onPause() {
super.onPause();
if (null != mOrientationListener) {
mOrientationListener.disable();
mOrientationListener = null;
}
}