0

我对警报对话框有一些问题...我如何调用 alert.show(); 在第二课中调用警报对话框?

我需要显示 alertdialog onReceive 方法,但我不能这样做......

有人可以帮我吗?

ps对不起我的英语..;|

主类:

    public class Main extends Activity {

    ...

     public void onTimeSet(TimePicker view, int hour, int minute) {

     ...


                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("ALARM");
                builder.setMessage("Wstajesz czy dalej drzemiesz ?!");

                builder.setPositiveButton("Wstaje...", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // Do do my action here

                        dialog.dismiss();
                    }

                });

                builder.setNegativeButton("Spie!", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // I do not need any action here you might
                        dialog.dismiss();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
                ....
    }

二等:

    public class Second extends BroadcastReceiver {

        @Override
        public void onReceive(Context k1, Intent k2) {

         /* 
           -->  here i want to call an alert using: alert.show(); It's possible ?

         */
        }
}
4

1 回答 1

0

你不能显示 a Dialogfrom a Receiver,你需要 a Activity。要么使用 anIntent来启动你MainActivity,要么根据你想要什么,ActivityDialog theme. 您可以通过创建一个并在您的主题Activity中声明它来做到这一点manifest

android:theme="@android:style/Theme.Dialog"

请注意,您需要Intent.FLAG_ACTIVITY_NEW_TASK在创建IntentReceiver开始时设置标志Activity

于 2013-06-19T21:54:48.780 回答