gpt4 book ai didi

android - 主要 Activity 从堆栈中移除 - 将使用状态设置为离线

转载 作者:搜寻专家 更新时间:2023-11-01 09:10:09 25 4
gpt4 key购买 nike

加载主要 Activity 后,我可以通过更新远程数据库行将登录用户的状态设置为在线。如果用户退出应用程序,我必须将用户状态设置为离线。

如果应用程序使用后退按钮退出,我有 onDestroy() 方法,在那里我可以将用户状态设置为离线,但如果我使用主页按钮退出,我从设置中终止应用程序 onDistroy() 不是打电话。

有没有办法知道主 Activity 何时不再在堆栈上,以便我可以更新用户的状态?

最佳答案

当用户点击后退或主页按钮时,将触发 onStop。所以在 onStop 中处理您的事件。

public void onStop () {
//do your stuff here
super.onStop()
}

编辑:

也试试

@Override
protected void onPause()

super.onPause();




}

你也可以让它检查应用程序是否完成

 if (this.isFinishing()){
//Insert your finishing code here

}

关于android - 主要 Activity 从堆栈中移除 - 将使用状态设置为离线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8789985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com