Note that there are some explanatory texts on larger screens.

plurals
  1. POThread causing error message on leaving and comes back to game app
    primarykey
    data
    text
    <p>After hitting home after playing my threaded game then hitting the apps icon, then hitting the icon for my app again, I get a "digger has quit unexpectedly error" and it brings me back to the general apps screen, I can hit my app icon again at this point and it brings me to the game and it runs fine. I expect there is something I should be doing with the thread to prevent that irritating message when I restart my app. maybe in an <code>onStop</code> or <code>onPause</code> method. here is my thread code fragments:</p> <pre><code>getHolder().addCallback( new SurfaceHolder.Callback() { //@Override public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true; gameLoopThread.setRunning(false); while (retry) { try { gameLoopThread.join(); retry = false; } catch (InterruptedException e) {} } } //@Override public void surfaceCreated(SurfaceHolder holder) { screenWidth =gameView.getWidth(); screenHeight = gameView.getHeight(); createSprites(); gameLoopThread.setRunning(true); gameLoopThread.start(); } //@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } }); </code></pre> <p>I have a gamethread class with this:</p> <pre><code>import android.graphics.Canvas; import android.view.SurfaceHolder; public class GameLoopThread extends Thread { static final long FPS = 10; private GameView view; private boolean running = false; public GameLoopThread(GameView view) { this.view = view; } public void setRunning(boolean run) { running = run; } @Override public void run() { long ticksPS = 200 / FPS; long startTime; long sleepTime; while (running) { Canvas c = null; startTime = System.currentTimeMillis(); try { c = view.getHolder().lockCanvas(); synchronized (view.getHolder()) { view.onDraw(c); } } finally { if (c != null) { view.getHolder().unlockCanvasAndPost(c); } } sleepTime = ticksPS - (System.currentTimeMillis() - startTime); try { if (sleepTime &gt; 0) sleep(sleepTime); else sleep(10); } catch (Exception e) {} } } } </code></pre> <p>one thing I tried was changing the surfaceDestroyed method to just;</p> <pre><code>public void surfaceDestroyed(SurfaceHolder holder) { gameLoopThread.setRunning(false); } </code></pre> <p>but that didn't help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload