我想知道是否可以注册一个事件,以便在用户关闭应用程序时捕获(即按回上一个 Activity 或类似的东西)。
谢谢
最佳答案
在您的MainActivity
中,您可以重写onBackPressed()
来了解用户何时按下后退按钮并进行适当的处理。
Called when the activity has detected the user's press of the back key. The default implementation simply finishes the current activity, but you can override this to do whatever you want.
您可以将其与 isTaskRoot()
结合使用来实现您所描述的内容。
Return whether this activity is the root of a task. The root is the first activity in a task.
关于java - 捕获应用程序关闭事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28928443/