Предотвратить повторное создание активности Android при выключении экрана

Как предотвратить воссоздание активности при выключении экрана?

What I do

Start Bejewels and go to the jewelry screen. Press power button shortly. The screen is turned off, but the device is not. Press power button again.

What I see

The same screen as before turning screen off.

В случае моего приложения (тривиальное, просто веб-приложение с одним WebView) сценарий выглядит следующим образом:

What I do

Start my app. The activity onCreate() method loads an URL into the WebView. Press power button shortly. The screen is turned off, but the device is not. Press power button again.

What I see

The WebView is reloading the page.

What I expected

As in Bejewels case I want to see the same screen, that for my app is the page in its previous state: scripts are running, a form fields are filled etc.

Отладка показала, что я ошибался (в предыдущем вопросе), а onDestroy () и onCreate () вызываются один за другим, когда экран только включен. И поскольку я все еще слышу музыку, которую играет сценарий, когда экран выключен, похоже, что и действие, и WebView существуют, пока я снова не нажму кнопку питания.

Что я пробовал

android:alwaysRetainTaskState="true" The same behavior. Reading about intents (to no avail, I just did not understand, how they are applied to my situation). Using PhoneGap. It behaves differently: just kills the whole application on pressing power button. This IS better, but not the best.

Ответы на вопрос(3)

Ваш ответ на вопрос