我正在使用andengine 开发安卓游戏。问题是当电源中断或屏幕锁定时我强制关闭错误。我的代码 n logcat 错误如下:
public class ScreenReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
wasScreenOn=true;
}else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT )){
wasScreenOn=true;
}
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
wasScreenOn=false;
}
}
//onresume方法
protected void onResume() {
if(wasScreenOn){
RESUME GAME
}
}
LOGCAT 错误:
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): FATAL EXCEPTION: main
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.m2f.StepUpPuzzle/com.m2f.StepUpPuzzle.GameActivity}: java.lang.NumberFormatException: unable to parse 'null' as integer
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1740)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1759)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2938)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread.access$1600(ActivityThread.java:155)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1003)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.os.Handler.dispatchMessage(Handler.java:130)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.os.Looper.loop(SourceFile:351)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at android.app.ActivityThread.main(ActivityThread.java:3826)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at java.lang.reflect.Method.invokeNative(Native Method)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at java.lang.reflect.Method.invoke(Method.java:538)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
12-21 12:26:07.016: ERROR/AndroidRuntime(1220): at dalvik.system.NativeStart.main(Native Method)