使用Microsft Exchange时,Android会激活用户每次打开设备时都需要通过的密码屏幕。
我正在制作一个使用由线程运行的SurfaceView的游戏。我使用了很多静态变量。如果在播放时关闭设备,当我回来并输入密码时,游戏屏幕显示但是某些位图的大小错误并被冻结。
在日志中,我首先看到非UI线程的NullPointerException,然后是ANR错误。看起来关闭设备已经破坏了我的应用程序的一些对象,但是当它返回时它没有再次通过onCreate和SurfaceView构造函数。
使用电话或点击HOME按钮暂停游戏时,我没有任何问题。此外,在其他两个设备上,游戏在游戏过程中将它们关闭后打开时效果很好,但它们没有安全屏幕。
我正在使用Galaxy Tab,os 2.2
修改 在线程中打印堆栈跟踪后,我得到了
android.graphics.Canvas.throwIfRecycled
似乎我的一些位图已被回收。知道如何在onResume或surfaceChanged()中检测到这一点,它总是在返回应用程序时触发?
答案 0 :(得分:0)
目前我解决此问题的方法是,如果没有使用正确的事件序列恢复此活动,则关闭此活动。如果onSurfaceChanged在没有首先发生onSurfaceCreated的情况下发生,则关闭此活动。游戏的状态仍然可以保留,当玩家重新启动此活动时,它将在停止的地方继续。
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
//if it does not start through surfaceCreated close activity
// because some bitmaps could be recycled and crash the application
if (!surfaceCreatedFirst){
_thread.setRunning(false); //stop the thread
((Activity) context1).finish(); //close activity
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
surfaceCreatedFirst = true;
_thread = new FootballThread(holder, this);
_thread.setRunning(true);
_thread.start();
}