I'm trying to change from menu activity to any other activity and the whole app stops responding, no idea why.
This is the code I use(I call it from the SurfaceView class instance of the activity):
Intent intent = new Intent(menuActivity, ExitActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("EXIT", true);
menuActivity.startActivity(intent);
Log:
10-28 13:03:38.278: E/AndroidRuntime(6185): FATAL EXCEPTION: main
10-28 13:03:38.278: E/AndroidRuntime(6185): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4224)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.ActivityThread.access$1400(ActivityThread.java:140)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.os.Looper.loop(Looper.java:137)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.ActivityThread.main(ActivityThread.java:4921)
10-28 13:03:38.278: E/AndroidRuntime(6185): at java.lang.reflect.Method.invokeNative(Native Method)
10-28 13:03:38.278: E/AndroidRuntime(6185): at java.lang.reflect.Method.invoke(Method.java:511)
10-28 13:03:38.278: E/AndroidRuntime(6185): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
10-28 13:03:38.278: E/AndroidRuntime(6185): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
10-28 13:03:38.278: E/AndroidRuntime(6185): at dalvik.system.NativeStart.main(Native Method)
10-28 13:03:38.278: E/AndroidRuntime(6185): Caused by: java.lang.NullPointerException
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:377)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.LoadedApk.getClassLoader(LoadedApk.java:320)
10-28 13:03:38.278: E/AndroidRuntime(6185): at android.app.LoadedApk.makeApplication(LoadedApk.java:493)
EDIT:
More code - constructor of the SurfaceView method:
private MenuActivity menuActivity;
public MenuPanel(Context context,MenuActivity activity) {
super(context);
menuActivity = activity;;
}
The whole activity code:
public class MenuActivity extends Activity {
private MenuPanel panel;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
panel = new MenuPanel(this,this);
panel.getHolder().setFormat(PixelFormat.RGBA_8888);
setContentView(panel);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
panel.onBackPressed(this);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
protected void onPause() {
panel.pauseGame();
super.onPause();
}
@Override
protected void onStop() {
//panel.recycleBitmaps();
// TODO Auto-generated method stub
super.onStop();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onResume() {
if (panel.getbPaused()) panel.resumeGame();
super.onResume();
}
}
EDIT2:
Also tried adding a method to the activity class and calling it from the surfaceview class but the result is the same.
EDIT3:
public class ExitActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}else {
Intent myIntent = new Intent(ExitActivity.this, SplashActivity.class);
ExitActivity.this.startActivity(myIntent);
}
}
}