LifeCycle android app

326
21 декабря 2016, 00:29

Вроде есть два приложения с похожей архитектурой. В одном после того, как развернул приложение, появляется в логе onRestart(); onResume(); в другом нет.. свернул приложение, последнее что вижу в логе onStope(); а когда снова разворачиваю - черный экран... и снова сворачиваю - лог не меняется. Почему может такое происходить? в каких случаях не вызываются методы onRestart(); 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
        }
    }
}
Answer 1

Вот несколько выдержек из одной умной книжки. может помочь:

The onResume function is executed after the OnStart event or after the current activity is switched to the background. When the user views this activity again, if it has not been destroyed, and if onStop events have not been performed (activities continue to exist in the task)...

After the onStop event is executed, if the activity and the process it resides in have not been systematically destroyed, or if the user views the activity again, the onRestart event(s) of the activity are executed. The onRestart event skips the onCreate event activities and directly executes the onStart events.

:

READ ALSO
Как распарсить VkApiPoll

Как распарсить VkApiPoll

Помогите распарсить VkApiPoll

243
Метод clone() для массива

Метод clone() для массива

Как правильно написать clone(), чтобы все элементы массива также копировались?

301
Как вызвать функцию по команде?

Как вызвать функцию по команде?

Предположим, у меня есть вот такая команда:

332
Галерея на Spring

Галерея на Spring

ПриветДелаю галерею которая отображает все фотографии в папке

256