被重新翻上屏幕关闭prevent安卓活动 [英] Prevent Android activity from being recreated on turning screen off
问题描述
如何prevent的活动被重新翻上屏幕关闭?
我做什么
- 开始Bejewels并转到珠宝画面。
- preSS电源按钮不久。屏幕被关闭,但该设备不是
- preSS电源按钮。
我看到
在同一屏幕旋转屏幕关闭之前。
在的情况下我的应用程序(小事一桩,只是一个web应用程序有一个单一的web视图)的方案如下:
我做什么
- 在开始我的应用程序。该活动的onCreate()方法加载一个URL到web视图。
- preSS电源按钮不久。屏幕被关闭,但该设备不是
- preSS电源按钮。
我看到
web视图被重新加载页面。
我的期望
作为Bejewels情况下,我希望看到同样的画面,这对于我的应用程序是在previous状态的页面:脚本运行,一个表单域 填充等。
调试结果显示,我错了(在previous问题)和的onDestroy()和的onCreate()的画面时,刚满上被称为一个接一个。而且因为我仍然听到音乐,通过一个脚本,当屏幕关闭时,它看起来像的活性和web视图确实存在,直到我再次preSS电源按钮播放。
我试过了。
- 机器人:alwaysRetainTaskState =真同样的行为
- 在阅读有关意图(没有用,我只是不明白,他们是如何应用到我的情况)。
- 使用PhoneGap的。它的表现是不同的:刚刚杀死在pressing电源按钮,整个应用程序。这是更好的,但不是最好的。
- 创建于Application.onCreate()的观点。
- 视图添加到布局中Activity.onCreate()。
- 从布局Activity.onDestroy删除视图()。
详情请看这里: <一href="http://stackoverflow.com/questions/10505346/attach-detach-android-view-to-from-layout">Attach/detach Android的视图/从布局
How to prevent an activity from being recreated on turning screen off?
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.
In case of my application (trivial one, just a web-app with a single WebView) the scenario is the following:
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.
Debugging showed, that I was wrong (in a previous question) and onDestroy() and onCreate() are being called one-by-one when the screen is just turned on. And since I still hear a music, played by a script, when the screen is off, it looks like both the activity and the WebView do exist until I press power button again.
What I tried.
- 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.
- Create the view in Application.onCreate().
- Add the view to a layout in Activity.onCreate().
- Remove the view from the layout in Activity.onDestroy().
Details are here: Attach/detach Android view to/from layout
这篇关于被重新翻上屏幕关闭prevent安卓活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!