Android:如果用户使用“最近使用的应用程序”按钮关闭应用程序,则控制操作发生

Android: Control action to happen if user closes app with Recent Apps Button

我的应用程序有一个可用性状态来显示用户是否在线,现在当用户关闭应用程序时,如果他在线,它会给出值 0 和 1。

现在,当用户使用最近使用的应用程序按钮关闭应用程序时,它没有 activity 生命周期,因此我无法控制发送用户离线信息的操作。

所以有什么解决方案能够控制当用户关闭应用程序和最近使用的应用程序时会发生什么?

更新 onPause() 中的用户在线状态。

onPause() 使用案例 Docs.

This callback is mostly used for saving any persistent state the activity is editing, to present a "edit in place" model to the user and making sure nothing is lost if there are not enough resources to start the new activity without first killing this one. This is also a good place to stop things that consume a noticeable amount of CPU in order to make the switch to the next activity as fast as possible.