被重新翻上屏幕关闭prevent安卓活动

编程入门 行业动态 更新时间:2024-10-27 00:31:49
本文介绍了被重新翻上屏幕关闭prevent安卓活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何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删除视图()。
  • 详情请看这里: 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安卓活动

    本文发布于:2023-11-27 01:20:25,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1635982.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:屏幕   prevent

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!