0

我在调用 RunOnUiThread 中的 AlertDialog 的 OnClick 事件中的方法时遇到问题。

下面的逻辑是在applyUpdate()方法执行时显示 ProgressDialog 。如果下载失败或仍在进行中,该方法返回 0。用户可以选择重新启动或继续下载。

The issue is that when Restart is selected the AlertDialog remains on the screen (with the button clicked).

doDownload() 是否在对话框关闭之前启动,是线程问题还是其他问题?

public void doApply(View view){
    progressDialog = ProgressDialog.show(UpdateForm.this, "", "Applying update...");

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            try{
                applyUpdate = nnEngine.applyUpdate();
            } catch (Exception e) {
                // Handle exception
            }

            // Check update result.
            progressDialog.dismiss();
            switch (applyUpdate) {
// Other cases removed.....
                case 0:
                    // Download in progress or failed.
                    AlertDialog.Builder inprogDlg = new AlertDialog.Builder(UpdateForm.this);
                    inprogDlg.setTitle("Download in progress or failed.");

                    inprogDlg.setPositiveButton("Continue download", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                        // Wrong button may be displayed.
                        notifyUser(null, checkDownloadButton);
                    }
                });

                inprogDlg.setNegativeButton("Restart download", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        doDownload(getWindow().getDecorView().findViewById(android.R.id.content));
                    }
                });

                inprogDlg.create().show();
                break;
            }
        }
    });
}
4

0 回答 0