AlertDialog未在Android中的runOnUIThread中显示

AlertDialog未在Android中的runOnUIThread中显示,android,multithreading,user-interface,background,Android,Multithreading,User Interface,Background,我试图从后台线程显示AlertDialog。因此,我使用rununui方法。调用该函数时不会出现问题。我也没有得到一个错误。我的代码: public void showingAlert(final String text){ activity.runOnUiThread(new Runnable() { public void run() { Log.e("Test","SHOWING DIALOG"); AlertDia

我试图从后台线程显示AlertDialog。因此,我使用rununui方法。调用该函数时不会出现问题。我也没有得到一个错误。我的代码:

 public void showingAlert(final String text){
    activity.runOnUiThread(new Runnable() {
        public void run() {
            Log.e("Test","SHOWING DIALOG");
            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(activity);
            }
            builder.create();
            builder.setTitle("Alert title")
                    .setMessage(""+text)
                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // continue with delete
                        }
                    })
                    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // do nothing
                        }
                    })
                    .setIcon(android.R.drawable.ic_dialog_info)
                    .show();
        }
    });
}
你知道是什么导致了这个问题吗?该类由MainActivity通过以下方式创建:
BackgroundClass=新的BackgroundClass(本);(这是来自Main活动的引用)。因此,活动对象由构造函数初始化。

请将其添加到第行以显示警报

 AlertDialog alertDialog = alertDialogBuilder.create();
 // show it
 alertDialog.show();
并从
builder

这里是完整的代码,你可以尝试,这是为我工作

 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity);
                alertDialogBuilder.setTitle("Alert");
                alertDialogBuilder.setMessage("message")
                        .setCancelable(false)
                        .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                           downloadAPk(mSelectedMovie);
                            }
                        })
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

请将此添加到行以显示警报

 AlertDialog alertDialog = alertDialogBuilder.create();
 // show it
 alertDialog.show();
并从
builder

这里是完整的代码,你可以尝试,这是为我工作

 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivity);
                alertDialogBuilder.setTitle("Alert");
                alertDialogBuilder.setMessage("message")
                        .setCancelable(false)
                        .setPositiveButton("Add", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                           downloadAPk(mSelectedMovie);
                            }
                        })
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

不幸的是,同样的结果。没有对话框也没有错误。它被另一个窗口覆盖。效果很好。谢谢。不幸的是,同样的结果。没有对话框也没有错误。它被另一个窗口覆盖。效果很好。谢谢。代码在我的手机中运行良好。有一些原因可能导致重用lt.1。方法
showingAlert
未被调用。2.
AlertDialog
被其他电话窗口覆盖。就是这样。它被另一扇窗户遮住了。非常感谢。该代码在我的手机中运行良好。有一些原因可能导致重用lt.1。未调用方法
showingAlert
。2.
AlertDialog
被其他电话窗口覆盖。就是这样。它被另一扇窗户遮住了。非常感谢你。