Android的 - 如何退出一个应用程序时,用户preSS home键? [英] Android - How to exit an app when user press the home button?

查看:169
本文介绍了Android的 - 如何退出一个应用程序时,用户preSS home键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何退出一个应用程序时,用户preSS主页按钮。

I want to know how to exit an app when user press the Home Button.

据我知道,主页按钮移动正在运行的应用程序在后台,并把启动过程在前面。

As far as i know that Home Button moves the running app in background and puts Launcher process in front.

我知道我可以使用结束(),但我不知道我应该说是因为我不知道它的功能是会得到一个电话时,用户将preSS home键。

I know i can use finish() but i don't know where i should call it because i have no idea which function is going to get a call when user will press the Home Key.

感谢。

推荐答案

根据您想要做的,压倒一切的是什么 onUserLeaveHint 可能是最好的选择:

Depending on what you want to do, overriding onUserLeaveHint might be the best bet:

http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint()

这将让您的应用程序知道您的应用程序正在退出,因为用户选择(通过按Home键或选择通知等)来切换应用程序。该提示功能的不可以被称为如果传入的电话(或类似)是导致您的应用程序去的背景下,因为用户没有主动行动。

This will let your app know that your app is being exited because the user chose to switch apps (Like by hitting the Home button or selecting a notification). This hint function will not be called if an incoming phone call (or similar) is causing your app to go to the background, as the user didn't initiate that action.

这篇关于Android的 - 如何退出一个应用程序时,用户preSS home键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆