【趣读官方文档】1.管家的抉择 (Android进程生命周期)
来源:互联网 发布:淘宝买家秀点赞没了 编辑:程序博客网 时间:2024/05/02 01:33
前言:
进程生命周期 ,又名 你丑你先死
Process Lifecycle
The Android system attempts to keep application process around for as long as possible, but eventually will need to remove old processes when memory runs low. As described in Activity Lifecycle, the decision about which process to remove is intimately tied to the state of the user's interaction with it. In general, there are four states a process can be in based on the activities running in it, listed here in order of importance. The system will kill less important processes (the last ones) before it resorts to killing more important processes (the first ones).
The foreground activity (the activity at the top of the screen that the user is currently interacting with) is considered the most important. Its process will only be killed as a last resort, if it uses more memory than is available on the device. Generally at this point the device has reached a memory paging state, so this is required in order to keep the user interface responsive.
A visible activity (an activity that is visible to the user but not in the foreground, such as one sitting behind a foreground dialog) is considered extremely important and will not be killed unless that is required to keep the foreground activity running.
A background activity (an activity that is not visible to the user and has been paused) is no longer critical, so the system may safely kill its process to reclaim memory for other foreground or visible processes. If its process needs to be killed, when the user navigates back to the activity (making it visible on the screen again), its
onCreate(Bundle)
method will be called with the savedInstanceState it had previously supplied inonSaveInstanceState(Bundle)
so that it can restart itself in the same state as the user last left it.An empty process is one hosting no activities or other application components (such as
Service
orBroadcastReceiver
classes). These are killed very quickly by the system as memory becomes low. For this reason, any background operation you do outside of an activity must be executed in the context of an activity BroadcastReceiver or Service to ensure that the system knows it needs to keep your process around.
Sometimes an Activity may need to do a long-running operation that exists independently of the activity lifecycle itself. An example may be a camera application that allows you to upload a picture to a web site. The upload may take a long time, and the application should allow the user to leave the application while it is executing. To accomplish this, your Activity should start a Service
in which the upload takes place. This allows the system to properly prioritize your process (considering it to be more important than other non-visible applications) for the duration of the upload, independent of whether the original activity is paused, stopped, or finished.
- 【趣读官方文档】1.管家的抉择 (Android进程生命周期)
- android官方文档之路--activity生命周期
- android进程的生命周期
- android进程的生命周期
- Android进程的生命周期
- Android进程的生命周期
- Android 官方文档之 -进程和线程
- Android官方开发文档Training系列课程中文版:管理Activity的生命周期之Activity的重建
- Android官方开发文档Training系列课程中文版:管理Activity的生命周期之启动一个Activity
- android的进程的生命周期
- Activity生命周期官方原文文档
- 【Android官方文档】翻译Android官方文档-AIDL(三)
- Android中进程的生命周期
- Android的进程与生命周期
- Android应用进程的生命周期
- Android 应用程序(进程)生命周期
- Android官方开发文档Training系列课程中文版:管理Activity的生命周期之暂停和恢复Activity
- Android官方开发文档Training系列课程中文版:管理Activity的生命周期之停止和重启Activity
- c++ --->vector容器总结
- AndroidStudio新建项目
- MySQL集群搭建详解(三种结点分离)
- HDU 2955 Robberies(01背包/对象转移)
- 大型网站系统架构的演化
- 【趣读官方文档】1.管家的抉择 (Android进程生命周期)
- poj 2251 Dungeon Master(BFS)
- 报表打印时提示页边距被设置到纸张可打印范围之外怎么办
- android studio gradle 友盟自动更新jar包 okio冲突
- Android自定义控件 -- 自定义ViewGroup
- Java垃圾回收GC(二)
- Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
- vs2015+ffmpeg开发环境配置
- 动画Animation两种实现方式的不同效果