如何关闭我的android系统pssed回$ P $应用 [英] How can I close my application on back pressed in android

查看:107
本文介绍了如何关闭我的android系统pssed回$ P $应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在主屏幕上走的时候我preSS装置的背部button.I现在用这个code ..

 公共无效onBack pressed(){
   this.finish();
   返回;
}


解决方案

pressing BACK键将有效地调用完成()为您服务。没有必要捕获返回键。

我假设你的问题是,当你preSS BACK键,它只是活动在你的应用程序要回previous。

如果是那么这样做的所有活动自我终结,当他们在你的应用程序启动一个新的活动 ...

  startActivity(新意图(这一点,MyNewActivity.class));
完();

如果你这样做,那么就没有活动返回,当你preSS回来了,它总是会返回到主屏幕。

I want to go on home screen when I press device's back button.I am using this code..

public void onBackPressed() {
   this.finish();
   return;
}

解决方案

Pressing the BACK key will effectively call finish() for you. There is no need to trap the BACK key.

I'm assuming your problem is that when you press the BACK key it is simply going back to the previous Activity in your app.

If that is the case then make all activities 'self-terminate' when they start a new Activity in your app....

startActivity(new Intent(this, MyNewActivity.class));
finish();

If you do that then there will be no Activity to return to when you press BACK and it will always return to the home screen.

这篇关于如何关闭我的android系统pssed回$ P $应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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