简体   繁体   English

最小化时如何关闭活动

[英]How to I make an activity close when minimised

I've made an app and I want the apps mainactivity to stop when the app's minimised. 我已经制作了一个应用程序,我希望在最小化该应用程序时停止其主要活动。 So when the app gets maximised again then it will be just like it opened fresh. 因此,当应用程序再次最大化时,它就像刚打开一样。

Thanks 谢谢

You should probably look at this function: onUserLeaveHint() 您可能应该看一下此函数: onUserLeaveHint()

Called as part of the activity lifecycle when an activity is about to go into the background as the result of user choice. 当活动由于用户选择而要进入后台时,称为活动生命周期的一部分。 For example, when the user presses the Home key... 例如,当用户按下Home键时...

You can call finish() in this function 您可以在此函数中调用finish()

Example how to override the function in your Activity: 示例如何在“活动”中覆盖函数的示例:

@Override
protected void onUserLeaveHint() {
    super.onUserLeaveHint();

    finish();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM