onBack pressed()不工作 [英] onBackPressed() not working

查看:94
本文介绍了onBack pressed()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图关闭一个后退按钮点击我的应用程序。从主屏幕上,后退按钮带你到一个学分屏幕。从这个学分屏幕上,我想与后退按钮关闭该应用程序。不幸的是,onBack pressed()方法。我打电话似乎并没有被所有执行。我不知道怎么办。

 包app.jonward.boss;
进口android.app.Activity;


公共类学分延伸活动{

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.credits);

    //做的东西
}


@覆盖
公共无效onBack pressed(){
   完();
   返回;
}

}
 

解决方案

我不明白这一点。什么 onBack pressed()做的的调用完成()完成()活动方法,有没有办法来退出你的应用程序,可以这么说。也许你真正想要的是叫完成()上正在启动积分活动活动。里面的其他活动:

 结束();
   startActivity(这一点,Credits.class);
 

I'm trying to close my app on a back button click. From the main screen, the back button takes you to a credits screen. From that credits screen, I want to close the app with the back button. Unfortunately, the onBackPressed() method I'm calling doesn't seem to be executed at all. I'm not sure how to proceed.

package app.jonward.boss;
import android.app.Activity;


public class Credits extends Activity{

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.credits);

    //Doing stuff
}


@Override
public void onBackPressed() {
   finish();
   return;
}

}

解决方案

I don't get it. What onBackPressed() does is to call finish(). finish() is an Activity method, there's no way to "quit" your app, so to speak. Perhaps what you really want is to call finish() on the Activity that is starting the Credits activity. Inside the other activity:

   finish();
   startActivity(this, Credits.class);

这篇关于onBack pressed()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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