【问题标题】:startActivity not waiting for Alert button to be clickedstartActivity 不等待警报按钮被点击
【发布时间】:2018-12-16 09:03:31
【问题描述】:

我有一个对话框提示用户确认删除。

用户点击删除后会弹出一个简单的警报。我需要重定向到一个新的活动,但在我有机会在确认警报上单击“确定”之前,startActivity 会启动。我已经添加了一条评论,它搞砸了。有什么想法吗?

 final AlertDialog.Builder alert = new 
AlertDialog.Builder(EventDetails.this);
                    alert.setMessage("Are you sure you want to delete 
your Issue?")
                            .setTitle(R.string.app_name)
                            .setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Configs.showPD("Please wait...", EventDetails.this);

                                    eventObj.put(Configs.ISSUES_DELETED_BY, "Deleted By User");
                                    Date now = new Date();

                                    eventObj.put(Configs.ISSUES_DELETED_DATE, now);
                                    eventObj.put(Configs.ISSUES_DELETED, true);
                                    eventObj.saveInBackground(new SaveCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            if (e == null) {
                                                Configs.hidePD();
                                                Configs.simpleAlert("Issue deleted!", EventDetails.this);



                                                // Does not wait for me to click "OK" after "Issue deleted!"
                                               Intent intent = new Intent(EventDetails.this, MyIssues.class);
                                               startActivity(intent);


                                            }


                                        }



                                    });
                                }
                            })
                            .setNegativeButton("Cancel", null)
                            .setIcon(R.drawable.logo);
                    alert.create().show();

谢谢!

【问题讨论】:

  • simpleAlert 代码在哪里
  • simpleAlert() 内部可能有一些显示警报的代码。在那个电话中,我愿意打赌有一个地方可以进行回调。那就是 startActivity() 调用。除了在开始活动之前显示它之外,您在这里所拥有的可能与警报无关。
  • 你们俩都是对的。谢谢!

标签: java android alert


【解决方案1】:

想通了! JoeHz 是正确的。

这是任何遇到此问题的人的代码。

   AlertDialog.Builder alert = new AlertDialog.Builder(EventDetails.this);
                                                alert.setMessage("Issue deleted!")
                                                        .setTitle(R.string.app_name)
                                                        .setIcon(R.drawable.logo)
                                                        .setPositiveButton("OK",
                                                                new DialogInterface.OnClickListener() {
                                                                    public void onClick(DialogInterface dialog, int which) {
                                                                        Intent intent = new Intent(EventDetails.this, MyIssues.class);
                                                                        startActivity(intent);
                                                                        finish();
                                                                    }
                                                                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 2017-12-19
    • 2020-09-30
    • 2019-06-06
    • 2021-12-07
    相关资源
    最近更新 更多