游戏崩溃时,设备的密码屏幕启用 [英] Game crashing when device's password screen enabled

查看:198
本文介绍了游戏崩溃时,设备的密码屏幕启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用的Microsft兑换,Android的激活它的密码屏幕至极用户需要每一个设备开机时通过。

When using Microsft Exchange, Android activates its password screen wich the user needs to pass every time the device is turned on.

我提出这是使用SurfaceView由一个线程运行游戏。我使用许多静态变量。而玩如果设备处于关闭状态,当我回来,并输入密码,游戏画面显示,但具有错误的大小,并冻结了一些位图。

I am making a game which is using SurfaceView run by a thread. I am using many static variables. If the device is turned off while playing, when I come back and enter the password, the game screen shows but with some bitmaps having wrong size and is frozen.

在日志中我看到那么ANR错误后,非UI线程先NullPointerException异常。它看起来像关掉设备已经摧毁了我的应用程序的一些对象然而,当回来的时候它没有通过的onCreate和SurfaceView构造去试。

In logs I see first NullPointerException with the non-UI thread then ANR error later. It looks like the turning the device off has destroyed some objects of my application yet it did not go through onCreate and the SurfaceView constructor again when it came back.

暂停游戏时用phonecall或点击HOME键我没有问题。同样在其他两个设备的比赛中的发挥中部图灵他们和关闭后能正常工作,但他们不具备安全屏幕。

I have no problems when pausing the game with a phonecall or clicking HOME button. Also on two other devices the game works fine after turing them off and on in the middle of the play, but they don't have the security screen.

我使用的Galaxy Tab,OS 2.2

I am using Galaxy Tab, os 2.2

编辑:
在线程中打印堆栈跟踪后,我得到

After printing a stacktrace in the thread, I get

android.graphics.Canvas.throwIfRecycled

android.graphics.Canvas.throwIfRecycled

看来,我的一些位图已被回收。任何想法如何在onResume或surfaceChanged()总是开枪返回到应用程序检测此?

It seems that some of my bitmaps have been recycled. Any idea how to detect this in onResume or in surfaceChanged() which always fire on returning to the application?

推荐答案

目前我解决这个问题是,如果它没有与事件的正确的顺序重新开始关闭此活动。如果onSurfaceChanged必有onSurfaceCreated发生,然后再关闭此活动。本场比赛的状态还是可以preserved当玩家重新启动这项活动将继续在那里停了下来。

At the moment my solution to this problem is to close this activity if it is not resumed with the right sequence of events. If onSurfaceChanged happens without onSurfaceCreated happening first, then close this activity. The state of the game can still be preserved and when the player relaunch this activity it will continue where it stopped.

    @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(); 
    }

这篇关于游戏崩溃时,设备的密码屏幕启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆