我正在开发一个使用AndEngine的Android应用程序。我尝试以这种方式重启活动:
private void restartActivity() {
startActivity(new Intent(this, TMXTiledMapExample.class));
finish();
}
此解决方案适用于大多数设备,但我意识到不是Nexus4。
事实上,我收到以下错误:
08-06 11:24:17.416: E/AndroidRuntime(6299): FATAL EXCEPTION: main
08-06 11:24:17.416: E/AndroidRuntime(6299): java.lang.NullPointerException
08-06 11:24:17.416: E/AndroidRuntime(6299): at org.andengine.ui.activity.BaseGameActivity.onResumeGame(BaseGameActivity.java:222)
08-06 11:24:17.416: E/AndroidRuntime(6299): at org.andengine.ui.activity.BaseGameActivity$4.run(BaseGameActivity.java:373)
08-06 11:24:17.416: E/AndroidRuntime(6299): at android.os.Handler.handleCallback(Handler.java:730)
08-06 11:24:17.416: E/AndroidRuntime(6299): at android.os.Handler.dispatchMessage(Handler.java:92)
08-06 11:24:17.416: E/AndroidRuntime(6299): at android.os.Looper.loop(Looper.java:137)
08-06 11:24:17.416: E/AndroidRuntime(6299): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-06 11:24:17.416: E/AndroidRuntime(6299): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 11:24:17.416: E/AndroidRuntime(6299): at java.lang.reflect.Method.invoke(Method.java:525)
08-06 11:24:17.416: E/AndroidRuntime(6299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-06 11:24:17.416: E/AndroidRuntime(6299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-06 11:24:17.416: E/AndroidRuntime(6299): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:3)
尝试重启这样的活动:
Intent intent = getIntent();
finish();
startActivity(intent);
答案 1 :(得分:0)
如果是这样的话,请关闭新活动
startActivity(new Intent(this,TMXTiledMapExample.class)); 光洁度();
首先改变完成()
结束(); startActivity(new Intent(this,TMXTiledMapExample.class));