我使用一个 receiver 每周来创建一个 alertbox。但是确获得错误:
Unable to add window -- token null is not for an application
代码如下:
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(); } }
慕桂英4014372
翻阅古今
相关分类