Application Fundamentals--Processes and lifecycles(进程生命周期)

[b]Processes and lifecycles---进程生命周期[/b]

The Android system tries to maintain an application process for as long as possible, but eventually it will need to remove old processes when memory runs low. To determine which processes to keep and which to kill, Android places each process into an "importance hierarchy" based on the components running in it and the state of those components. Processes with the lowest importance are eliminated first, then those with the next lowest, and so on. There are five levels in the hierarchy. The following list presents them in order of importance:

翻译:Android 系统通常总是尽可能延长应用程序所属进程的生命期的,但是,系统最终还是会因为系统资源问题要关闭进程的。关闭进程之前,系统需要判定哪些进程需要继续维持哪些可以被关闭,Android系统是根据每个进程上关联的组件实例以及组件实例的最新状态做为判定每个进程重要程度的依据的,最低重要程度的进程将首先被系统关闭, 重要程度共分五个等级(重要程度1-5逐次降低,重要程度在这里也可以理解成系统维护进程等级):

1. A foreground process is one that is required for what the user is currently doing. A process is considered to be in the foreground if any of the following conditions hold:---翻译:符合下列四个条件的进程属于[b]前端进程[/b](foreground process):

* It is running an activity that the user is interacting with (the Activity object's onResume() method has been called).--翻译:进程中存在某个activity实例,该实例处于和用户交互状态。(该实例的onResume()方法已经被系统调用)。

* It hosts a service that's bound to the activity that the user is interacting with.--翻译:进程中某个服务被绑定到某个正在与用户交互的activity实例上。

* It has a Service object that's executing one of its lifecycle callbacks (onCreate(), onStart(), or onDestroy()).
--翻译:进程中某个Service实例的回调方法:onCreate(), onStart(), 或 onDestroy()正在被系统执行。

* It has a BroadcastReceiver object that's executing its onReceive() method.---翻译:进程中某个BroadcastReceiver实例的onReceive()方法正在执行中(广播消息响应处理中)。

Only a few foreground processes will exist at any given time. They are killed only as a last resort — if memory is so low that they cannot all continue to run. Generally, at that point, the device has reached a memory paging state, so killing some foreground processes is required to keep the user interface responsive.

翻译:由于系统同时只能维护少数几个前端进程,系统关闭前端进程是最不得以的做法,比如内存不足以维持前端进程的运行的时候才会发生。另外,为了保证与用户快速交互,某些前端进程也会被系统关闭的。

2.A visible process is one that doesn't have any foreground components, but still can affect what the user sees on screen. A process is considered to be visible if either of the following conditions holds:

翻译:可视进程中没有任何组件处于前台与用户交互,但是在屏幕上对用户视觉还是影响,符合下面条件的进程属于[b]可视进程[/b]:

* It hosts an activity that is not in the foreground, but is still visible to the user (its onPause() method has been called). This may occur, for example, if the foreground activity is a dialog that allows the previous activity to be seen behind it.---翻译:进程中某个activity组件实例已经不在前台,但是对于用户而言依然是可见状态(该实例的 onPause() 方法已经被系统调用过),例如,当前处于前台与客户交互的是一个对话框,那么前一个activity界面作为背景依然是用户可见状态。

* It hosts a service that's bound to a visible activity.---翻译:进程中某个服务实例与某个可视状态的activity有着绑定关系。

A visible process is considered extremely important and will not be killed unless doing so is required to keep all foreground processes running.---翻译:[b]可视进程[/b]是非常重要的,除非系统需要维护所有的前端进程,否则可视进程是不会被系统关闭的。

3. A service process is one that is running a service that has been started with the startService() method and that does not fall into either of the two higher categories. Although service processes are not directly tied to anything the user sees, they are generally doing things that the user cares about (such as playing an mp3 in the background or downloading data on the network), so the system keeps them running unless there's not enough memory to retain them along with all foreground and visible processes.

翻译:[b]服务进程[/b] ,是正在运行某个由 startService() 方法启动的服务的进程,尽管说[b]服务进程[/b]并没有直接与用户发生交互,但是它所做的事是用户关注的事,比如在后台播放MP3音乐或是在后台通过网络下载数据,所以系统通常总是维持这样的进程的,除非前端进程、可视进程需要更多内存的时候。可以这样理解前端进程、[b]可视进程[/b]的重要程度要高于[b]服务进程[/b]。

4. A background process is one holding an activity that's not currently visible to the user (the Activity object's onStop() method has been called). These processes have no direct impact on the user experience, and can be killed at any time to reclaim memory for a foreground, visible, or service process. Usually there are many background processes running, so they are kept in an LRU (least recently used) list to ensure that the process with the activity that was most recently seen by the user is the last to be killed. If an activity implements its lifecycle methods correctly, and captures its current state, killing its process will not have a deleterious effect on the user experience.

翻译:[b]后台进程[/b] 是持有某个当前用户不可见的activity实例的进程,(被持有的Activity实例的 onStop() 方法已经被系统调用过). [b]后台进程[/b]就用户体验来说没有什么影响,一旦[b]前端进程[/b]、[b]可视进程[/b]或[b]服务进程[/b]需要更多内存资源,系统将会随时杀死[b]后台进程[/b]。通常有很多[b]后台进程[/b]会处于系统维护中状态,系统把所有这些后台进程放在一个 LRU (least recently used) list中,这样做的目的是保证最后被用户看到的activity所属的进程总是最后一个被系统杀死。只要一个activity的回调方法被开发者正确实现、并能够及时俘捉到自身最新状态信息,那么,该实例所属的进程即使被系统关闭也不会影响到客户体验的。

5.An empty process is one that doesn't hold any active application components. The only reason to keep such a process around is as a cache to improve startup time the next time a component needs to run in it. The system often kills these processes in order to balance overall system resources between process caches and the underlying kernel caches.

翻译:[b]空进程[/b]是不持有应用的任何组件实例的进程。系统维护这样的进程的目的是处于缓存的考虑,可以提高组件实例的启动效率。系统也常常杀死这样的进程以换取系统资源、进程缓存、底层核心缓存之间的平衡。

Android ranks a process at the highest level it can, based upon the importance of the components currently active in the process. For example, if a process hosts a service and a visible activity, the process will be ranked as a visible process, not a service process.

翻译:Android系统尽可能授予进程更高的维护级别,具体说是根据当前进程中关联的activity实例的状态来给定当前进程维护级别,例如一个进程中关联到一个服务和一个可视的activity实例,该进程将被给定为[b]可视[/b]级别。

In addition, a process's ranking may be increased because other processes are dependent on it. A process that is serving another process can never be ranked lower than the process it is serving. For example, if a content provider in process A is serving a client in process B, or if a service in process A is bound to a component in process B, process A will always be considered at least as important as process B.

翻译:另外,一个进程的系统维护级别可能会由于被其他进程依赖而提高,被依赖的进程的级别总是高于依赖进程。例如:进程A中的内容提供组件是为进程B的一个组件服务的,或是如果进程A中的一个服务实例被绑定到进程B的某个组件实例,那么进程A至少具有和进程D同样的系统维护级别。

Because a process running a service is ranked higher than one with background activities, an activity that initiates a long-running operation might do well to start a service for that operation, rather than simply spawn a thread — particularly if the operation will likely outlast the activity. Examples of this are playing music in the background and uploading a picture taken by the camera to a web site. Using a service guarantees that the operation will have at least "service process" priority, regardless of what happens to the activity. As noted in the Broadcast receiver lifecycle section earlier, this is the same reason that broadcast receivers should employ services rather than simply put time-consuming operations in a thread.

翻译:由于[b]服务进程[/b](执行某个服务的进程)的系统维护级别总是高于某个关联了一个activity实例的[b]后台进程[/b]的系统维护级别,这就意味这[b]服务进程[/b]要比这个关联了一个activity实例的[b]后台进程[/b]活的更长。所以,使用[b]服务[/b]执行长时间操作要比使用一个activity实例来执行同样的耗时操作要更为合适。例如:后台音乐播放和把用照相功能俘获的图像信息上次到某个网站这样 的耗时操作,如果使用的是服务组件,那么当前进程就是[b]服务进程[/b]维护级别。在Broadcast receiver lifecycle章节中,也说到过类似的问题,都是出于同样的考虑,广播接收组件实例的onReceive()方法中不应该用独立线程的方式执行耗时操作,而是应该使用服务组件执行这样的操作。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
毕业设计,基于SpringBoot+Vue+MySQL开发的社区医院管理系统,源码+数据库+毕业论文+视频演示 信息数据从传统到当代,是一直在变革当中,突如其来的互联网让传统的信息管理看到了革命性的曙光,因为传统信息管理从时效性,还是安全性,还是可操作性等各个方面来讲,遇到了互联网时代才发现能补上自古以来的短板,有效的提升管理的效率和业务水平。传统的管理模式,时间越久管理的内容越多,也需要更多的人来对数据进行整理,并且数据的汇总查询方面效率也是极其的低下,并且数据安全方面永远不会保证安全性能。结合数据内容管理的种种缺点,在互联网时代都可以得到有效的补充。结合先进的互联网技术,开发符合需求的软件,让数据内容管理不管是从录入的及时性,查看的及时性还是汇总分析的及时性,都能让正确率达到最高,管理更加的科学和便捷。本次开发的社区医院管理系统实现了病例信息、字典表、家庭医生、健康档案、就诊信息、前台、药品、用户、用户、用户表等功能。系统用到了关系型数据库中王者MySql作为系统的数据库,有效的对数据进行安全的存储,有效的备份,对数据可靠性方面得到了保证。并且程序也具备程序需求的所有功能,使得操作性还是安全性都大大提高,让社区医院管理系统更能从理念走到现实,确确实实的让人们提升信息处理效率。 关键字:社区医院管理系统;信息管理,时效性,安全性,MySql
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值