It seems there are two applications with similar architecture. In one, after the application is deployed, it appears in the onRestart () log; onResume (); in the other there is no .. minimized the application, the last thing I see in the onStope () log; and when I deploy it again - the black screen ... and again I turn it off - the log does not change. Why can this happen? in which cases the onRestart () methods are not called; onResume ()?

@Override public void run() { Canvas canvas; while(running){ canvas = null; try{ canvas= this.surfaceHolder.lockCanvas(null); if (canvas == null) continue; synchronized(surfaceHolder){ this.gamePanel.update(); this.gamePanel.onDraw(canvas); } } finally{ if(canvas!=null){ surfaceHolder.unlockCanvasAndPost(canvas); } } } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.d(TAG,"surfaceChanged"); } @Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG,"surfaceCreated"); thread.setRunning(true); thread.start(); } @Override public void surfaceDestroyed(SurfaceHolder holder) { Log.d(TAG,"surfaceDestroyed"); //посылаем потоку команду на закрытие и дожидаемся, //пока поток не будет закрыт. boolean retry = true; thread.setRunning(false); // ну жна ли эта строка. без нее после сворачивания игры черный экран. while (retry) { try { thread.join(); retry = false; } catch (InterruptedException e) { // пытаемся снова остановить поток thread } } } 

    2 answers 2

    Here are a few excerpts from one smart book. may I help:

    The onResume function is activated after the current activity. If you haven’t been destroyed yet, you can’t ...

    It has been noted that the process has been carried out. The onStart event skips the onStreate event.

    Activation Life Cycle :

    • nothing helped. I have seen it more than once. after onStop () nothing happens onRestart () or onCreate (). And in the other exactly the same application, everything works. I can’t even find a difference in the code and understand why everything starts in one project and not in another. - Turalllb
    • I have no problems with a black screen when I use expands SurfaceView implements SurfaceHolder.Callback. - Turalllb
    • put logs in the overridable methods SurfaceHolder.Callback. namely, surfaceChanged, surfaceCreated, surfaceDestroyed. and here is the result. if you click on the screen lock, onPause onSaveInstanceState Stopping is called ... but the game continues to go, sounds are heard .. (why? like the same stop?) after everything is restored onRestart, onStart, onResume. But if you do not block the screen, but click back or minimize the application, then onPause and surfaceDestroyed .. why is surfaceDestroyed called? and how to fix it. - Turalllb
    • @Turalllb show the code? - dramf
    • Does @Turalllb onStop run at all? what do logs show? in both applications. As far as I understand, androyd does not guarantee the time of the onStop call. Try to put logs (different) on onFreeze, onPause and onStop, press the buttons and see at what point what event occurs. - dramf

    I solved the problem, I don’t remember what exactly was the solution, but the main ones: the variable that starts the while (running) game loop is passed immediately from the onPause method in order to stop the calculations in the stream sooner. If the stream is not busy with calculations, it will stop faster. The main problem was that the game loop started immediately after OnResume. After I started the game cycle by pressing the Continue button, the white screen problem disappeared.