我需要在后退按钮点击时最小化Android应用程序 [英] I need to minimize the android application on back button click
本文介绍了我需要在后退按钮点击时最小化Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在按下后退按钮时最小化应用程序。
I need to minimize the application when back button is pressed.
我使用以下代码来捕获硬件后退按钮点击事件
I use following code to catch hardware back button click event
帮助我按下后退键的最小化代码
help me with the code of minimize on back key pressed
@Override
public boolean onKeyDown(int keyCode, keyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_BACK;
//minimize application
return true;
}
return super.onKeyDown(keyCode, event);
}
推荐答案
我认为你需要将返回
事件视为 home
事件。下面的代码是当我按下返回
按钮时按下 home
的方式:
I think that you need to treat back
event as home
event. The code below is how I emulate home
pressed when User press back
button:
public void minimizeApp() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
这篇关于我需要在后退按钮点击时最小化Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文