机器人 - onBack pressed()不是为我工作为我、机器人、不是、工作

由网友(干戈挽惆怅)分享简介:我有一个程序的第一个活动是一个闪屏,第二个是在日志中,三是列表视图菜单活动,然后2等活动在3秒后启动画面消失,如果在日志中复选框记得我被选中它直接到菜单页面我重写菜单中的活动pssed功能onBack $ P $,这样它会退出程序后直接在用户单击后退从菜单中,但如果我已经通过其他活动了它不退出没有它去到$ P在堆栈...

我有一个程序的第一个活动是一个闪屏,第二个是在日志中,三是列表视图菜单活动,然后2等活动 在3秒后启动画面消失,如果在日志中复选框记得我被选中它直接到菜单页面 我重写菜单中的活动pssed功能onBack $ P $,这样它会退出程序后直接在用户单击后退从菜单中,但如果我已经通过其他活动了它不退出没有它去到$ P在堆栈和对话框$ pvious活动不出来它实际上不会出现第二个没少和desapper马上 这是我的onBack pressed功能

i have a program the first activity is a splash screen and the second is the log in and the third is list view menu activity and then 2 other activities the splash screen disappear after 3 seconds and if the log in check box remember me is checked it goes directly to the menu page i Override the onBackPressed function in the menu activity so that it will exit the program directly after the user click back from the menu but if i have gone through the other activities it doesn't exit no it goes to the previous activity in the stack and the dialog box doesn't come out it actually does appear for a second no less and desapper right away here is my onBackPressed function

    public void onBackPressed() {
   // TODO Auto-generated method stub
  // super.onBackPressed();
   AlertDialog.Builder builder = new AlertDialog.Builder(this);
   builder.setMessage("Are you Sure want to close the Application..?")
           .setCancelable(false)
           .setTitle("EXIT")
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                   dialog.cancel();
               }
           })
           .setPositiveButton("Yes",
                   new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           finish();
                       }
                   });
   AlertDialog alert = builder.create();
   alert.show();
   //super.onBackPressed();

}

推荐答案

我会建议你使用动作条在下面的意见建议的WarrenFaith。请检查下面的链接了解更多信息。

I would suggest you to use ActionBar as suggested by WarrenFaith in the comments below. Pls check the link below for more information

http://developer.android.com/design/patterns/navigation.html

下面是一个教程一样

http://www.vogella.com/articles/AndroidActionBar/article.html

您可以使用此。然而,这也似乎是一个不好的设计。您可以查看下面的评论知道为什么

You can use this. However this also seems to be a bad design. You can check the comments below to know why

 @Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
    onBackPressed();

}

return super.onKeyDown(keyCode, event);
}

public void onBackPressed() {
Intent myIntent = new Intent(MyActivity.this, MainActivity.class);

myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myIntent);
finish();
return;
    }

翁后退按钮pressed Inn的当前活动,当你回来preSS清除活性堆栈和naviagate到MainActivity。

Onn back button pressed inn your current activity when you back press you clear the activity stack and naviagate to MainActivity.

此外,我建议没有显示在后退按钮preSS一个警告对话框。它是一种糟糕的设计。为此,可以搜索。我读同样的,由commonsware回答

Also i would suggest no to display a alert dialog on back button press. Its a bad design. You can search on SO. i read the same and was answered by commonsware

阅读全文

相关推荐

最新文章