每次Power键的时候,app是会强制回到竖屏状态的,并且会重新调用Activity的onCreate(),当然很多时候这不是我们想要的。所以就需要用到android:configChanges了,在配置文件里设置<wbr style="line-height:25px"><span style="color:#0000ff; line-height:25px">android:configChanges="keyboardHidden|orientation"</span><wbr style="line-height:25px"><span style="color:#003366; line-height:25px">,这样在屏幕方向改变的时候就不会重新调用Activity的onCreate(),而是调用onConfigurationChanged(),然后在Activity里重载下</span><br style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px"> publicvoidonConfigurationChanged(ConfigurationnewConfig){<br style="line-height:25px"> super.onConfigurationChanged(newConfig);<br style="line-height:25px"> if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){<br style="line-height:25px"> //横向<br style="line-height:25px"> }else{<br style="line-height:25px"> //竖向<br style="line-height:25px"> }<br style="line-height:25px"> }</span><br style="line-height:25px"> 一般就这么处理下就可以了,要命的是用到了SurfaceView,而SurfaceView和Thread的生命周期是不一样的,唉,这里要说一下Google提供的sample了,里边有bug!!<br style="line-height:25px"> 由于每次Power键的时候会调用SurfaceView的surfaceDestroyed(SurfaceHolderholder),但是回到app的时候又没有执行surfaceCreated(SurfaceHolderholder),于是就咯屁了~~<br style="line-height:25px"> 目前想到一个能解决的方案是在onConfigurationChanged(ConfigurationnewConfig)里手动处理,<span style="color:#99cc00; line-height:25px">surfaceDestroyed(SurfaceHolderholder)</span>+<span style="color:#808000; line-height:25px">surfaceCreated(SurfaceHolderholder)</span>+<span style="color:#339966; line-height:25px">pause()</span>处理。。。<br style="line-height:25px"> 唉,希望可以找到一个比较好的解决方案吧。</wbr></wbr>