Jump to content
  • Advertisement
Sign in to follow this  
LAURENT*

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

This topic is 661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Edited by C0lumbo

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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();
        }

Share this post


Link to post
Share on other sites

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);
            }
        }
    }
Edited by LAURENT*

Share this post


Link to post
Share on other sites

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();
            }
        }
Edited by LAURENT*

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!