Android什么时候销毁activity而不销毁整个进程?

When does Android destroy activity without destroying the entire process?

我想了解和模拟 Android 何时调用我的 activity、onDestroy() 而不会破坏整个过程 。我不会打电话给 finish(),我想让 Android 自行销毁我的 activity。

来自activity-lifecycle documentation

The system never kills an activity directly to free up memory. Instead, it kills the process in which the activity runs, destroying not only the activity but everything else running in the process, as well.

但是 Android Activity documentation 说:

This (onDestroy) can happen because [...] the system is temporarily destroying this instance of the activity to save space.

那么是哪一个呢? Android 内存不足时会破坏活动,还是只会杀死整个进程?

我想模拟 Android 杀死 activity 而不是杀死整个进程的情况。 我可以通过使用“不保留活动”开发人员模式设置来模仿这一点,但我想了解这在现实世界中是如何发生的。

I want to make Android destroy my activity on it's own.

Android 不会这样做,除非通过您的操作(例如,finish())或用户操作(例如,返回导航、配置更改)。

So which one is it?

前者(Android 杀死进程,而不是活动)。参见 this answer from the woman who wrote this stuff. FWIW, also see this decade-old blog post of mine