Get Exception when showing Alert Dialog from Service - Unable to add window — token null is not for an application

后端 未结 5 1742
遥遥无期
遥遥无期 2020-12-06 19:11

Get Exception when showing Alert Dialog from Service.

Following is the code in my Service class: I am trying to show an AlertDialog.

But I get the error: Una

5条回答
  •  感情败类
    2020-12-06 19:53

    Try this.

    AlertDialog.Builder alertDialog  = new AlertDialog.Builder(myContext);
    

    Edit.

    Sorry about no comment. Put Context which started your service like a instance in service and use it.

    class SomeService 
    {   
         private final Context myContext;
         public WebService(Context myContext) 
         {
    
            this.myContext= myContext;
         }
    
       public void showDialog()
       {
            AlertDialog d = new AlertDialog.Builder(myContext);
       }
    }
    

提交回复
热议问题