开发者

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

开发者 https://www.devze.com 2022-12-19 07:17 出处:网络
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.Build

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;
  } }); 
0

精彩评论

暂无评论...
验证码 换一张
取 消