Everytime I exit my app and return.....

Started by
15 comments, last by Kylotan 7 years, 4 months ago

Everytime I exit my app and return it give me an error. The error is "Your game has stopped working", after this I need to tap my app's icon again to reactive it. Most apps allow the user to resume their session after exiting. I want to do the same. I'm new to java and android and have no idea where this error might be. does anyone have a club what I must do?

I'm running my apps on my phone because my laptop isn't strong enough.

I followed this guy's tutorial BTW

Advertisement

2 suggestions:

1. Try debugging it.

2. If that fails, check logcat.

If your app uses OpenGL then try looking into setPreserveEGLContextOnPause. Without it, when your app moves into the background, the OpenGL context and all associated objects are trashed and must be recreated.

2 suggestions:

1. Try debugging it.

2. If that fails, check logcat.

I found the log cat. It was consistence until I did my error process. Here a snap shot of the log cat errors.

http://i.imgur.com/y1FaTbb.png

There isn't a lot of code. Maybe, possibly, if it is not too much trouble, look into your soul and check the code?

The item in blue within the sea of red is clickable. If you click on that that it will take you to the line of code this causing the crash.

Developer with a bit of Kickstarter and business experience.

YouTube Channel: Hostile Viking Studio
Twitter: @Precursors_Dawn

The only thing it leads me to is this. What wrong with the code? I copied it perfectly.

The item in blue within the sea of red is clickable. If you click on that that it will take you to the line of code this causing the crash.



@Override
        public void surfaceCreated(SurfaceHolder holder){

            bg = new BackGround(BitmapFactory.decodeResource(getResources(), R.drawable.grassbg1));
            player = new Player(BitmapFactory.decodeResource(getResources(),R.drawable.helicopter), 100, 86, 3 );

            /*/NO USAGE
            smoke = new ArrayList<Smokepuff>();
            smokeStartTime = System.nanoTime();*/


            //cystalPoint = new CystalPoint(BitmapFactory.decodeResource(getResources(),R.drawable.redcyrstal), 91, 86, 1);
            cystalPoint = new ArrayList<CystalPoint>();
            cystalPoint.add(new CystalPoint(BitmapFactory.decodeResource(getResources(),R.drawable.redcyrstal), 91, 86, 1));

            //Safely start game loop
            thread.setRunning(true);
            thread.start();
        }
Read the error message. Note where it says "Thread already started" at "thread.start()". Fix that. Don't start a thread that is already started.

Read the error message. Note where it says "Thread already started" at "thread.start()". Fix that. Don't start a thread that is already started.

Okay I think I understand however I'm still lost. I have this code. When I use something called "try" I set the game's bool variable named "running" to false and that should be enough.


@Override 
public void surfaceDestroyed(SurfaceHolder holder) {
            //Safely end the program

            boolean retry = true;
            int counter = 0;
            while (retry == true && counter < 1000) {

                counter++;
                try {
                    thread.setRunning(false);
                    thread.join();
                    retry = false;
                } catch (InterruptedException e) { e.printStackTrace();}

            }
        }

 public void setRunning(boolean b)
    {
        running = b;
    }

@Override
    public void run() {
        long startTime;
        long timeMillis;
        long waitTime;
        long totalTime = 0;
        int frameCount = 0;
        long targetTime = 1000 / FPS;


        while (running == true) {
            startTime = System.nanoTime();
            canvas = null;


            //Try locking the canvas for pixel editing
            try {
                canvas = this.surfaceHolder.lockCanvas();

                synchronized (surfaceHolder) {

                    this.gamePanel.update();
                    this.gamePanel.draw(canvas);
                }
            } catch (Exception e) {}


            finally {
                if (canvas != null){
                    try {
                        surfaceHolder.unlockCanvasAndPost(canvas);
                    }catch (Exception e){e.printStackTrace();}
                }

            }

            timeMillis = (System.nanoTime() - startTime) / 1000000;
            waitTime = targetTime - timeMillis;

            try {
                this.sleep(waitTime);
            } catch (Exception e) {}

            totalTime += System.nanoTime() - startTime;
            frameCount++;

            if (frameCount == 30) {
                averageFPS = 1000/ ((totalTime/frameCount) / 1000000);
                frameCount = 0;
                totalTime = 0;

                System.out.println(averageFPS);
            }
        }
    }

After 2 nights of failure I'm back. Please help.

Read the error message. Note where it says "Thread already started" at "thread.start()". Fix that. Don't start a thread that is already started.

I tried but nothing is working. I tried making a Boolean variable and setting it to false and then setting it to true right after the "thread.start" function. The app doesn't give me the error anymore, it gives me a blank black screen, I have to restart the app to get it to work. I tried in various ways.....

Unlike c++ there was a lot of stuff automatically done for me that I just accepted but I'm really having a hard time figuring out where this program starts. I know if I could just get a clue how to look at the beginning I know I could solve this.


@Override
        public void surfaceCreated(SurfaceHolder holder){

            if (threadStarted == false) {
            bg = new BackGround(BitmapFactory.decodeResource(getResources(), R.drawable.grassbg1));
            player = new Player(BitmapFactory.decodeResource(getResources(), R.drawable.helicopter), 100, 86, 3);

            /*/NO USAGE
            smoke = new ArrayList<Smokepuff>();
            smokeStartTime = System.nanoTime();*/


            //cystalPoint = new CystalPoint(BitmapFactory.decodeResource(getResources(),R.drawable.redcyrstal), 91, 86, 1);
            cystalPoint = new ArrayList<CystalPoint>();
            cystalPoint.add(new CystalPoint(BitmapFactory.decodeResource(getResources(), R.drawable.redcyrstal), 91, 86, 1));
            cystalPoint.add(new CystalPoint(BitmapFactory.decodeResource(getResources(), R.drawable.redcyrstal), 91, 86, 1));

            //Safely start game loop
            thread.setRunning(true);
           // thread.threadHasBeenMade(true);

                threadStarted = true;
                thread.start();
            }
        }

If you can't debug it, write output to the log file so you can see which bits of the code are being executed and what various values are.

This topic is closed to new replies.

Advertisement