Issues with reopening game after close


Last Updated:

  1. Panthersgba

    Panthersgba Member This Topic's Starter

    Joined:
    Jan 5, 2010
    Messages:
    16
    Likes Received:
    0
    Hey guys,
    I have been working on a game, but I can't seem to get it to reopen where it leaves off if you hit the home button. I don't know how I need to set up the onCreate and stuff. I had put in a few things, but it keeps force closing when I try to open it back up and gives me this logcat

    E/AndroidRuntime( 183): Uncaught handler: thread main exiting due to uncaught e xception E/AndroidRuntime( 183): java.lang.IllegalThreadStateException: Thread already s tarted. E/AndroidRuntime( 183): at java.lang.Thread.start(Thread.java:1286) E/AndroidRuntime( 183): at com.Waldev.cannon.CannonBlast$panel.surfaceCr eated(CannonBlast.java:515) E/AndroidRuntime( 183): at android.view.SurfaceView.updateWindow(Surface View.java:392) E/AndroidRuntime( 183): at android.view.SurfaceView.onWindowVisibilityCh anged(SurfaceView.java:182) E/AndroidRuntime( 183): at android.view.View.dispatchWindowVisibilityCha nged(View.java:3745) E/AndroidRuntime( 183): at android.view.ViewGroup.dispatchWindowVisibili tyChanged(ViewGroup.java:690) E/AndroidRuntime( 183): at android.view.ViewGroup.dispatchWindowVisibili tyChanged(ViewGroup.java:690) E/AndroidRuntime( 183): at android.view.ViewRoot.performTraversals(ViewR oot.java:694) E/AndroidRuntime( 183): at android.view.ViewRoot.handleMessage(ViewRoot. java:1613) E/AndroidRuntime( 183): at android.os.Handler.dispatchMessage(Handler.ja va:99) E/AndroidRuntime( 183): at android.os.Looper.loop(Looper.java:123) E/AndroidRuntime( 183): at android.app.ActivityThread.main(ActivityThrea d.java:4203) E/AndroidRuntime( 183): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 183): at java.lang.reflect.Method.invoke(Method.java:5 21) E/AndroidRuntime( 183): at com.android.internal.os.ZygoteInit$MethodAndA rgsCaller.run(ZygoteInit.java:791) E/AndroidRuntime( 183): at com.android.internal.os.ZygoteInit.main(Zygot eInit.java:549) E/AndroidRuntime( 183): at dalvik.system.NativeStart.main(Native Method)

    I am not sure exactly what to do with what I have to make it work, I just know that the thread is still running and I need to keep surfaceCreated from going I guess. Here are my onCreate and surface stuff

    public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    }

    public boolean onKeyDown(int keyCode, KeyEvent event){
    if(keyCode == KeyEvent.KEYCODE_MENU){
    if(panelStuffz.getState() != -11){
    panelStuffz.setPreviousState(panelStuffz.getState());
    panelStuffz.setState(-11);
    return true;
    }
    if(panelStuffz.getState() == -11){
    panelStuffz.setState(panelStuffz.getPreviousState());
    }
    }
    return false;
    }

    @Override
    public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

    }

    public void surfaceCreated(SurfaceHolder holder) {
    thread.setRunning(true);
    thread.start();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
    // simply copied from sample application LunarLander:
    // we have to tell thread to shut down & wait for it to finish, or else
    // it might touch the Surface after we return and explode
    boolean retry = true;
    thread.setRunning(false);
    while (retry) {
    try {
    thread.join();
    retry = false;
    } catch (InterruptedException e) {
    // we will try it again and again...
    }
    }
    }

    any ideas? My friends and I have been stumped : /
     

    Advertisement
  2. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    Hi Panthersgba

    For future reference, could you post code and log lines in CODE tags please, so that indentation & layout are preserved and they're easier to read.

    It's hard to know if this will be relevant in your case, but do you handle onPause and onResume? In my game that's where I stop my game thread and start it again, and deal with other resource loading activities.

    Code (Text):
    1.  
    2.     @Override
    3.     protected void onResume() {
    4.         // Ideally a game should implement onResume() and onPause()
    5.         // to take appropriate action when the activity looses focus
    6.         super.onResume();
    7.         m_GLSurfaceView.onResume();
    8.  
    9.         GameSound.loadSounds(this) ;
    10.         if( m_gameStarted ) {
    11.             m_gameThread = new GameThread(m_game) ;
    12.             m_gameThread.start() ;         
    13.         }
    14.        
    15.         startSensor() ;
    16.     }
    17.  
    18.     @Override
    19.     protected void onPause() {
    20.         // Ideally a game should implement onResume() and onPause()
    21.         // to take appropriate action when the activity looses focus
    22.         super.onPause();
    23.         m_GLSurfaceView.onPause();
    24.         GameSound.releasePool() ;
    25.  
    26.         if( m_gameThread!=null ) {
    27.             m_gameThread.stopGame() ;
    28.             m_gameThread = null ;          
    29.         }
    30.        
    31.         stopSensor() ;
    32.     }
    33.    
    34.     @Override
    35.     protected void onStop() {
    36.         super.onStop();
    37.         GameSound.releasePool() ;
    38.  
    39.         if( m_gameThread!=null ) {
    40.             m_gameThread.stopGame() ;
    41.             m_gameThread = null ;
    42.             m_gameStarted = false ;
    43.         }
    44.     }
    45.  
    Just a suggestion.

    Mark
     
  3. Panthersgba

    Panthersgba Member This Topic's Starter

    Joined:
    Jan 5, 2010
    Messages:
    16
    Likes Received:
    0
    Alright, sorry about that, I'm not sure how to use this sites stuff yet...but thanks for the info, I do not have onResume, onPause, or onStop in there. I will work on that. I am pretty sure I saw a flow chart on this on developer.android.com so I will go look there before I ask anything else
     

Share This Page

Loading...