Android杀死所有活动问题

时间:2015-06-14 04:56:13

标签: android

在我的项目中,我在我的布局上放了一个下拉菜单按钮,但不知道如何杀死所有活动。请告诉我解决方案我是android的新手。

我正在做这样的事情。

 button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Creating the instance of PopupMenu
            PopupMenu popup = new PopupMenu(DataListActivity.this, button1);
            //Inflating the Popup using xml file
            popup.getMenuInflater()
                    .inflate(R.menu.popup_menu, popup.getMenu());

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {

                    AlertDialog.Builder a_builder = new AlertDialog.Builder(DataListActivity.this);
                    a_builder.setMessage("Do You Want To Close This App !!!")
                            .setCancelable(false)
                            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int id) {
                                    Intent intent = new Intent(getApplicationContext(), MainMenu.class);
                                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                    intent.putExtra("EXIT", true);
                                    startActivity(intent);
                                    //finish();
                                }
                            })
                            .setNegativeButton("No" , new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                }
                            });
                    AlertDialog alert = a_builder.create();
                    alert.setTitle("Alert !!!");
                    alert.show();
                    // Toast.makeText(
                    //   MainMenu.this,
                    //   "You Clicked : " + item.getTitle(),
                    //  Toast.LENGTH_SHORT
                    // ).show();
                    return true;
                }
            });

            popup.show(); //showing popup menu
        }
    });

1 个答案:

答案 0 :(得分:1)

在你写的行上:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

将其更改为:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

这应该对你有帮助。

相关问题