[Solved]Android app not restarting properly

My android app does not restart properly. When I exit it with the back button, all the methods (onPause, onStop…) are called and my app instance becomes null. However, when I try to reopen the app I only see black. My app’s simpleInitApp is not called. The only way to fix this is to open the latest apps menu and manually kill my app.
My android activity:
package com.grizeldi.lsfmobile;

import com.jme3.app.DefaultAndroidProfiler;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import com.grizeldi.lsfmobile.Main;
import com.jme3.app.AndroidHarnessFragment;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
public class MainActivity extends Activity {
     * Note that you can ignore the errors displayed in this file,
     * the android project will build regardless.
     * Install the 'Android' plugin under Tools->Plugins->Available Plugins
     * to get error checks and code completion for the Android project files.
    private Main main = Main.app;
    public MainActivity(){
        // Set the default logging level (default=Level.INFO, Level.ALL=All Debug Info)
    protected void onCreate(Bundle savedInstanceState) {
        // Set window fullscreen and remove title bar
        // find the fragment
        FragmentManager fm = getFragmentManager();
        AndroidHarnessFragment jmeFragment =
                (AndroidHarnessFragment) fm.findFragmentById(R.id.jmeFragment);
        // uncomment the next line to add the default android profiler to the project
        //jmeFragment.getJmeApplication().setAppProfiler(new DefaultAndroidProfiler());
        new Thread(new Runnable() {
            public void run() {
                while (main == null){
                    main = Main.app;
                main.mainActivity = MainActivity.this;
                Logger.getLogger("").info("Passed main activity to Main class.");
    public static class JmeFragment extends AndroidHarnessFragment {
        public JmeFragment() {
            // Set main project class (fully qualified path)
            appClass = "com.grizeldi.lsfmobile.Main";
            // Set the desired EGL configuration
            eglBitsPerPixel = 24;
            eglAlphaBits = 0;
            eglDepthBits = 16;
            eglSamples = 0;
            eglStencilBits = 0;
            // Set the maximum framerate
            // (default = -1 for unlimited)
            frameRate = -1;
            // Set the maximum resolution dimension
            // (the smaller side, height or width, is set automatically
            // to maintain the original device screen aspect ratio)
            // (default = -1 to match device screen resolution)
            maxResolutionDimension = -1;
            // Set input configuration settings
            joystickEventsEnabled = false;
            keyEventsEnabled = true;
            mouseEventsEnabled = true;
            // Set application exit settings
            finishOnAppStop = true;
            handleExitHook = true;
            exitDialogTitle = "Do you want to exit?";
            exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";
            // Set splash screen resource id, if used
            // (default = 0, no splash screen)
            // For example, if the image file name is "splash"...
            //     splashPicID = R.drawable.splash;
            splashPicID = 0;

Any ideas on this? It’s driving me nuts… :rage:

I remember having the issue…
Android does not properly shut down the app and tries somehow to reuse stuffs when you launch it again… idk how it’s done, but it’s just messing things up.
So in all my games I force kill the android app brute force.
like this

    public void onDestroy() {
        if (bp != null) {
        //forcing process killing to avoid bad things to happen when restarting the application

you could give it a try.


And bp is?

Just pasting this into my onDestroy does the job. Shouldn’t this be in MainActivity by default?

Yeah sorry bp is the BillingProcessor :stuck_out_tongue:
You don’t need that part :wink:

1 Like