应用程序结束时,所有的活动,会发生什么? [英] What happens when all activities of an application finishes?

查看:115
本文介绍了应用程序结束时,所有的活动,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序四项活动,可以说A,B,C和D有一个 Constants.java 类,它扩展了应用程序应用程序类,以维持全球应用程序状态。常量类有应用程序的所有的常数变量。活动流程是这样的 A - > b - > C - > d 。当后退按钮正从活动一pressed,我打电话结束()方法,这将完成的活动时,并关闭应用程序。之后,如果我从所有的应用程序打开的应用程序,没有在 Constants.java ,其值从去年推出后继续存在的变量。同样的事情是不会发生的时候我在做 System.exit(10)然后按 Process.killProcess(Process.myPid())从活动A(背pressed)。

I've four activities in my Android Application, lets say A, B, C and D. There is one Constants.java class in the app which extends Application class in order to maintain global application state. The Constants class have all the constants variables of the app. The activity flow is like this A-->B-->C-->D. When back button is being pressed from Activity A, I'm calling finish() method which will finishes the activity A and closes the application. After that if I'm opening the app from all apps, there is a variable in Constants.java whose value persists from the last launch. The same thing is not happening when I'm doing System.exit(10) followed by Process.killProcess(Process.myPid()) from activity A(on back pressed).

  1. 将在完成所有活动,通过调用完成每项活动的()将关闭应用程序(它的过程)?
  2. 如何把一个变量的值仍然存在,即使它的一切活动都结束(关闭)?
  3. 是公平调用 System.exit(10)然后按 Process.killProcess(Process.myPid())用于退出应用程序?
  1. Will finishing all activities by calling finish() of each activity will close the Application(Its process)?
  2. How the value of a variable persists even if its all activities are finished(closed)?
  3. Is it fair to call System.exit(10) followed by Process.killProcess(Process.myPid()) for exiting the application?

如何才能清除应用程序的退出申请常数(返回$ P $的HomeActivity的PSS)?

Update:

How can I clear the application constants on exit of the application(Back press of the HomeActivity)?

推荐答案

1)不,Android不保证如此。它是由操作系统来决定是否结束处理或不

1) No, Android does not guarantee so. It's up to the OS to decide whether to terminate the process or not.

2)因为活动实例仍然住在Dalvik虚拟机。在Android中每个进程都有一个独立的Dalvik虚拟机。

2) Because the Activity instance still lives in the Dalvik VM. In Android each process has a separate Dalvik VM.

每个进程都有自己的虚拟机(VM),所以应用程序的   code运行在从其他应用程序隔离。

Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.

当你调用完成()这并不意味着活动实例进行垃圾回收。你是说Android的要的代码的的活动(不显示它了)。它仍然是present直到安卓决定终止该进程(并因此终止DVM)或实例当作垃圾回收。

When you call finish() this doesn't mean the Activity instance is garbage collected. You're telling Android you want to close the Activity (do not show it anymore). It will still be present until Android decides to kill the process (and thus terminate the DVM) or the instance is garbage-collected.

Android的启动过程中,当任何应用程序的组件   需要被执行,然后关闭过程中,当它不再   需要或当系统必须恢复存储器用于其它应用

Android starts the process when any of the application's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other applications.

3)我不会这么做,除非你有一些非常有力的理由。作为一个经验法则,你应该当我们的Andr​​oid手柄杀死你的应用程序,除非有东西在你的应用程序状态,需要一个应用程序复位时,它失去焦点。

3) I wouldn't do so unless you have some very strong reason. As a rule of thumb, you should let Android handle when to kill your application, unless there's something in your application state that requires an application reset when it loses focus.

行情来源

这篇关于应用程序结束时,所有的活动,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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