我每周都使用接收器制作一个警报框。但是我在下面的代码中遇到以下错误
无法添加窗口 - 令牌 null 不适用于应用程序
我正在使用的代码是
public class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
try {
displayAlert("Have you seen your chiropractor this month?", "Alert!", context);
}
catch (Exception e)
{
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
public void displayAlert(final String error, String title, final Context context)
{
new AlertDialog.Builder(context.getApplicationContext()).setMessage(error)
.setTitle(title)
.setCancelable(true)
.setNeutralButton("Continue",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
dialog.cancel();
Intent newIntent = new Intent(context, Appointment.class);
context.startActivity(newIntent);
}
})
.show();
}
}