onBack pressed()不工作工作、onBack、pressed

2023-09-06 14:22:25 作者:跳舞的小丑ワ

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

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


公共类学分延伸活动{

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

    //做的东西
}


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

}
 

解决方案

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

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

PR停止工作的解决办法

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);

 
精彩推荐
图片推荐