Android: display a Dialog from an AppWidget
Issue When you want to display a dialog, you don’t only need a context, you need an activity context. From an activity, displaying a dialog is pretty straightforward: Display a dialog from an activity new AlertDialog.Builder(MyActivity.this) .setTitle("Dialog title") .setMessage("Dialog message") .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Handle a positive answer } }) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Handle a negative answer } }) .setIcon(R.drawable.ic_dialog_alert) .show(); Okay, that’s a pretty usual code sample. But what about displaying it from an app-widget?