当应用程序处于前台时,内存中将包含Application对象的实例、所有活动的实例(未被杀死)以及从根之一引用的所有对象引用(尚未进行垃圾回收)。
> 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.
2) 当应用程序进入后台时,Android框架会在某些时候执行以下操作:
a) 终止用于应用程序目的的整个进程,这将从内存中完全擦除所有对象。
> These processes have no direct impact on the user experience. Provided
> they implement their Activity life-cycle 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.
b) 仅结束活动(实质上不会删除任何其他对象引用),保存它们的状态,创建活动堆栈并离开其他所有内容(应用程序对象、任何其他静态对象、可从任何根可达的引用)。
部分地解释如2.a.所述
> 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.
Source - developer.android.com