我的警告对话框有问题...我如何调用alert.show();在第二类中调用警报对话框?
我需要显示alertdialog onReceive方法,但我不能这样做......
有人可以帮我吗?
P.S。对不起我的英文..; |
主要类别:
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 ?
*/
}
}
答案 0 :(得分:0)
您无法从Dialog
展示Receiver
,您需要Activity
。使用Intent
开始MainActivity
或根据您的具体要求,将其Activity
与Dialog theme
分开。您可以通过创建Activity
并在主题为manifest
的情况下将其声明为
android:theme="@android:style/Theme.Dialog"
请注意,在Intent.FLAG_ACTIVITY_NEW_TASK
创建Intent
以开始Receiver
Activity
标记