tags:

views:

94

answers:

1

Why can't I use the Context of a Service to display an AlertDialog ?

I can do it with Toast!

A: 

It may not be as implicit as Toast.makeText() but in the constructor for AlertDialog.Builder it takes in a Context as a parameter.

// creates an AlertDialog to the instance of the Context
alertDialog = new AlertDialog.Builder(this).create(); 
alertDialog.setTitle("Alert 1");
alertDialog.setMessage("This is an alert");
// display your dialog with an OK button.
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {
    return;
  } }); 
Anthony Forloney