为什么android的“复苏”崩溃的应用程序? [英] why does android 'revives' crashing apps?

查看:127
本文介绍了为什么android的“复苏”崩溃的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你有一个Android应用程序,有一个以上的活动,以及活动A开始B,所以如果b活动崩溃的进程被终止,而是由Android操作系统恢复并重新开始,而不是仅仅关闭应用程序活动A,为什么呢?

if you have an android app that has more than one Activity, and Activity A starts B, so if Activity b crashes the process is killed but is revived by android OS and starts Activity A again instead of just shutting down the app, why ?

推荐答案

您正在抱怨说,Android将试图在崩溃后正常恢复应用程序的状态? ;)

You're complaining that Android will attempt to recover your app's state gracefully after a crash? ;)

这是Android的资源管理的结果,并在工作中的活动周期。请记住,一个任务可以被一些活动可能跨越几个进程或应用程序组成。由于此处概述: http://android-developers.blogspot.com /2010/04/multitasking-android-way.html Android的过程不会在传统的* nix的过程中感觉停摆干净。您的应用程序的组件接收生命周期事件,但某个点后,应用程序可以在没有进一步的警告被杀死,使系统可以回收其资源。

This is the result of Android's resource management and the Activity lifecycle at work. Keep in mind that a single task can be composed of a number of Activities that may span several processes or apps. As outlined here: http://android-developers.blogspot.com/2010/04/multitasking-android-way.html Android processes don't shut down "cleanly" in the traditional *nix process sense. Your app's components receive lifecycle events but after a certain point the app can be killed without further warning so that the system may reclaim its resources.

例如,用户可能会浏览网页,点击一个YouTube链接启动YouTube应用程序,然后点击共享按钮启动他们喜爱的社交网络应用程序,并上传视频链接。这是相同的任务的一部分;如果用户presses回来好几次,他们会回来的,因为它们从启动浏览器的页面。

For example, a user might be browsing the web, click a youtube link launching the youtube app, then click a share button to launch their favorite social networking app and post the video link. This is all part of the same task; if the user presses back several times they'll come back to the page in the browser that they started from.

一旦你开始了社交网络应用程序,系统可能会决定它的运行内存不足,这会杀了关闭浏览器的过程中,以腾出更多。 (毕竟,它不是在前面,用户不会注意到。)当用户presses后退按钮返回到浏览器的活动它被重新启动,并重新在用户离开时的最后状态。在最坏的情况,用户会遇到短暂的延迟,而事情重新初始化。

Once you start up the social networking app, the system might decide that it's running low on memory and it's going to kill off the browser's process to free up more. (After all, it's not in front and the user won't notice.) When the user presses the back button to return to the browser Activity it gets restarted and reconstructs the last state where the user left it. At worst the user experiences a short delay while things reinitialize.

但是,这同样的事件恢复previous活动状态可以即使在以相同的过程相同的应用程序发生的序列。在您的情况,b活动关闭,崩溃的结果。因此,该系统不正是它总是这样 - 它返回到previous活动:活动A.但活动A的过程中是不是仍然存在(它坠毁!),所以在系统重新启动它,它可以重建其previous状态。

But this same sequence of events restoring a previous Activity state can happen even within the same app in the same process. In your scenario, Activity B closed as the result of the crash. So the system does exactly what it always does - it returns to the previous Activity: Activity A. But Activity A's process isn't still around (it crashed!) so the system restarts it and it can reconstruct its previous state.

这篇关于为什么android的“复苏”崩溃的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆