- 前台进程 该进程包含正在与用户进行交互的界面组件,比如一个Activity
- 可视进程 该进程中的组件虽然没有和用户交互,但是仍然可以被看到
- 服务进程 该进程包含在执行后台操作的服务组件,比如播放音乐的进程
- 后台进程 该进程包含的组件没有与用户交互,用户也看不到
- 空进程 没有任何界面组件、服务组件,或触发器组件**
Android系统是进程托管的,也就是说进程都是由系统来管理,系统会按照特定的算来来回收这些进程。在回收中秉承几个原则
1. 尽量延长进程的生命周期,不到必须的情况下不会回收,因为系统回收进程会影响用户体验
2. 按优先级从低到高进行回收
3. 同等优先级的进程越近使用越晚回收。
进程过一段时间后是会被回收的,但要遵循上面的这些原则,播放音乐的这个进程的优先级还是比较高的,所以被莫名其妙地回收的可能性不大,在播放音乐时平白无故地停止这样的情况很少对吧?service和application的生命周期有关,只要进程被回收,那么它所占用的所有资源将被回收。
An important and unusual feature of Android is that an application process's lifetime is notdirectly controlled by the application itself. Instead, it is determined by the system through a combination of the parts of the application that the system knows are running, how important these things are to the user, and how much overall memory is available in the system.
-
A foreground process is one holding an Activity at the top of the screen that the user is interacting with (its onResume() method has been called) or an IntentReceiver that is currently running (its onReceiveIntent() method is executing). There will only ever be a few such processes in the system, and these will only be killed as a last resort if memory is so low that not even these processes can continue to run. Generally at this point the device has reached a memory paging state, so this action is required in order to keep the user interface responsive.
-
一个前台进程是:持有一个Activity ,该活动是与用户进行交互(其onResume() 方法已被调用过)的顶层屏幕或一个正在运行的IntentReceiver (其 onReceiveIntent() 方法正在执行)。系统中只有少数这样的进程,系统只有在内存低至无法运行这些进程时,才会最后选择杀掉这些进程。通常此时设备达到一个内存分页调度状态,该动作用于保证用户交互是可响应的。 -
A visible process is one holding an Activity that is visible to the user on-screen but not in the foreground (its onPause() method has been called). This may occur, for example, if the foreground activity has been displayed with a dialog appearance that allows the previous activity to be seen behind it. Such a process is considered extremely important and will not be killed unless doing so is required to keep all foreground processes running.
-
一个可视进程是:持有一个用户组屏幕上可见的Activity,但不是位于前景(其 onPause() 方法已被调用过)。比如,当前景的活动已经显示,一个对话框出现,则之前的活动则在其之后可见。这类进程被认为非常重要,不会被杀掉,除非杀掉该进程是为了保持所有前台进程处于运行状态。
-
A service process is one holding a Service that has been started with the startService()method. Though these processes are not directly visible to the user, they are generally doing things that the user cares about (such as background mp3 playback or background network data upload or download), so the system will always keep such processes running unless there is not enough memory to retain all foreground and visible process.
-
一个服务进程是:持有一个通过startService() 方法启动的Service。尽管这些进程并非对用户可见,它们通常处理一些用户关心的事情(比如后台mp3播放器或后台网络数据上传下载),所有系统总是尽量保持这些进程运行,除非没有足够的内存保证所有前台进程和可视进程运行。
-
A background process is one holding an Activity that is not currently visible to the user (its onStop() method has been called). These processes have no direct impact on the user experience. Provided they implement their activity lifecycle correctly (see Activity for more details), the system can kill such processes at any time to reclaim memory for one of the three previous processes types. Usually there are many of these processes running, so they are kept in an LRU list to ensure the process that was most recently seen by the user is the last to be killed when running low on memory.
-
一个后台进程是:持有一个当前对用户不可见的Activity (其onStop() 方法已被调用)。这些进程对用户的体验没有直接影响。如果其持有的活动的生命周期相关方法被正确实现(更多细节请看 Activity ),系统会在任何时候杀掉这些进程以回收内存供前三种进程使用。通常会有很多这类进程运行,他们被保存在一个LRU列表内,保证最新被用户看到的进程在系统内存过低时最晚被系统杀掉。
-
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 of its application needs to run. As such, the system will often kill these processes in order to balance overall system resources between these empty cached processes and the underlying kernel caches.
-
一个空进程是:没有持有任何活动的应用程序组件。保持这样一个进程的唯一理由是在下一次一个应用程序的组件需要运行时作为缓存来加快启动速度。同样,系统会经常杀掉这些进程以在空的缓存进程和底层内核缓存之间保持系统资源平衡。