Android 解决屏幕旋转时重启onCreate方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010886975/article/details/53516514

在对应的Activity注册的时候添加

 android:configChanges="orientation|keyboardHidden|screenSize"

就行了。
还可以在这个Activity中添加如下代码对屏幕旋转进行监听:

@Override  
    public void onConfigurationChanged(Configuration newConfig) {  
     // TODO Auto-generated method stub  
         super.onConfigurationChanged(newConfig);  
             if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {  
                 // 监听横屏 
             } else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {  
                 // 监听竖屏 
             }  
     }  

猜你喜欢

转载自blog.csdn.net/u010886975/article/details/53516514