Android 实现DialogFragments以警告从BroadcastReceiver运行的对话框

Android 实现DialogFragments以警告从BroadcastReceiver运行的对话框,android,broadcastreceiver,android-alertdialog,android-dialogfragment,Android,Broadcastreceiver,Android Alertdialog,Android Dialogfragment,我试图理解如何使用对话框片段从广播接收器运行警报对话框,该接收器模拟吐司按摩 然而,下面的警报对话框运行良好,但每次警报对话框从广播接收器调用时,都会中断用户,停止视频播放并关闭键盘…等等 我试图使用片段并从广播接收器调用show()方法,但最终一无所获 下面是我使用的警报对话框活动: public class Alertactivity extends Activity { @SuppressWarnings("ResourceType") @Override public

我试图理解如何使用对话框片段从广播接收器运行警报对话框,该接收器模拟吐司按摩

然而,下面的警报对话框运行良好,但每次警报对话框从广播接收器调用时,都会中断用户,停止视频播放并关闭键盘…等等

我试图使用片段并从广播接收器调用show()方法,但最终一无所获

下面是我使用的警报对话框活动:

public class Alertactivity  extends Activity {

    @SuppressWarnings("ResourceType")
    @Override
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.Theme_Transparent);
    super.onCreate(savedInstanceState);
        String mynames[] = { };

        int rando = (int) (Math.random() * xx);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        final AlertDialog alertDialog = builder.create();

                alertDialog.getWindow().setLayout(600, 400);

        LayoutInflater inflater = alertDialog.getLayoutInflater();

        int k = (int) (Math.random() * 5);

        final View dialoglayout = inflater.inflate(new int[]{R.layout.mycustom_toast, R.layout.mycustom_toastx, R.layout.mycustom_toastx1, R.layout.mycustom_toastx2, R.layout.mycustom_toastx3}[k], null);

        Object localObject2;

        localObject2 = (TextView) ((View) dialoglayout).findViewById(R.id.toastText);
        ((TextView) localObject2).setText(mynames[rando]);

        (alertDialog).setView((View) dialoglayout);
        alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));


        WindowManager.LayoutParams wlp = alertDialog.getWindow().getAttributes();


    Window window = alertDialog.getWindow();


        int j = (int) (Math.random() * 8);
        wlp.gravity = new int[]{Gravity.CENTER, Gravity.LEFT, Gravity.RIGHT, Gravity.BOTTOM, Gravity.TOP, Gravity.TOP, Gravity.CENTER_HORIZONTAL, Gravity.CENTER_VERTICAL}[j];

        wlp.dimAmount = 0.0f;
        alertDialog.show();
    this.setFinishOnTouchOutside(true);

                   dialoglayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Alertactivity.this.finish();
            }
        });

        alertDialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialoglayout) {

                Alertactivity.this.finish();

            }
        });


        Timer mTimer = new Timer();
        mTimer.schedule(new TimerTask() {

            public void run() {

                Alertactivity.this.finish();
            }
        }, 10000);


   }

}
并且每套时间从广播接收器调用该活动:

 Intent startIntent = new Intent(paramContext, Alertactivity.class);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            paramContext.startActivity(startIntent); 

我需要做的是在警报对话框片段中实现此警报,以避免中断用户并停止任何视频播放或关闭键盘“如果用户正在键入”等等

我不知道您是否能找到,但如果我正在开发应用程序,我会弹出一个通知,而不是一个对话框。因此,点击通知,你可以打开你的对话框,如果你想。因为我知道吐司通知是不可点击的!有没有一种方法可以创建一个可点击的toast?不要像我说的那样创建toast,创建一个通知。如果你想要某种可点击的烤面包,可以使用SnackBar。我不知道你是否能找到,但是如果我在开发应用程序,我会弹出一个通知,而不是一个对话框。因此,点击通知,你可以打开你的对话框,如果你想。因为我知道吐司通知是不可点击的!有没有一种方法可以创建一个可点击的toast?不要像我说的那样创建toast,创建一个通知。如果你想要某种可点击的烤面包,可以使用SnackBar。