Why can't I use the Context of a Service to display an AlertDialog
Why can't I use the Context of a Service to display an AlertDialog ?
I can do it w开发者_高级运维ith Toast!
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;
} });
精彩评论