After I minimize the application, onPause is onPause and after several seconds
surfaceDestroyed D/MainThread: Game loop executed 3314 times D/Menu: onSaveInstanceState D/Menu: Stopping... and for these seconds, the minimized application continues to work, the game cycle in the additional stream is running. Has he been trying to stop the flow all this time? On the emulator, everything happens instantly. FURTHER I expand the game is called without delay
onRestart D/Menu: onStart D/Menu: onResume D/MainThread: surfaceCreated D/MainThread: surfaceChanged D/MainThread: Starting game loop The last frame at which the flow was stopped hangs on the screen, sounds from the game are heard, the flow is working, the game cycle is spinning, after several seconds a black screen, the sound shows everything continues to work and only then at the same time as the I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3e491adf time:279057271 everything starts to appear.
also log messages: Skipped 1804 frames! The application may be doing too much work on its main thread. Skipped 1804 frames! The application may be doing too much work on its main thread. something hangs in the main thread .. but there's nothing there. (and again I repeat on the emulator everything is fine). and the same log
:I/art: Thread[7,tid=6517,WaitingInMainSignalCatcherLoop,Thread*=0x557106fc10,peer=0x22c070a0,"Signal Catcher"]: reacting to signal 3 I/art: Wrote stack traces to '/data/anr/traces.txt' Now I’m trying to find the file traces.txt but it seems I don’t read it without root .. I can’t even find it in the system
why on the emulator such a log and everything works as it should.
D/Menu: onPause D/Menu: onSaveInstanceState D/Menu: Stopping... D/MainThread: surfaceDestroyed And on the phone
D/Menu: onPause (тут иногда немножко подвисает, игра свернута но поток работает, иногда подвисает на долго) D/MainThread: surfaceDestroyed D/Menu: onSaveInstanceState D/Menu: Stopping... MORE THAN I noticed: onPause is fast because the log is D / Menu: onPause is displayed after execution.
public void run() { Canvas canvas; long tickCount= 0L; long beginTime;// время начала цикла long timeDiff;// время выполнения шага цикла int sleepTime;// сколько мс можно спать (<0 если выполнение опаздывает) int framesSkipped;// число кадров у которых не выполнялась операция вывода графики на экран sleepTime=0; long x, x1; while(running){ tickCount++; canvas = null; // пытаемся заблокировать canvas // для изменение картинки на поверхности try{ this.time.onTickUpdate(); canvas= this.surfaceHolder.lockCanvas(null); if (canvas == null) continue; synchronized(surfaceHolder){ beginTime=System.currentTimeMillis(); framesSkipped=0;// обнуляем счетчик пропущенных кадров this.gamePanel.update();// формируем новый кадр this.gamePanel.Draw(canvas);//Рисуем // вычисляем время, которое прошло с момента запуска цикла timeDiff=System.currentTimeMillis()- beginTime; sleepTime=(int)(FRAME_PERIOD - timeDiff); // вычисляем время, которое можно спать if(sleepTime>0){ // если sleepTime > 0 все хорошо, мы идем с опережением try { // отправляем поток в сон на период sleepTime Thread.sleep(sleepTime); } catch(InterruptedException e){} } while(sleepTime<0 && framesSkipped< MAX_FRAME_SKIPS){ this.gamePanel.update(); sleepTime+= FRAME_PERIOD; framesSkipped++; } } } finally{ // в случае ошибки, плоскость не перешла в //требуемое состояние if(canvas!=null){ surfaceHolder.unlockCanvasAndPost(canvas); } } x = System.currentTimeMillis() - beginTime; x1 = 1000/x; System.out.println("FPS= " + x1); } Log.d(TAG,"Game loop executed "+ tickCount+" times"); }
surfaceDestroyedandD/Menu: onSaveInstanceState. - post_zeew