android - How to display AlertDialog in BroadcastReceiver -


i trying display alertdialog in 1 of methods of broadcastreceiver's subclass. set

            if(telisinthedatabase == true){                  string checkid = dbhelp.getidbysimcardnumber(tel);                  layoutinflater minflater = layoutinflater.from(thisclasscontext);                  view statusupdateview = minflater.inflate(r.layout.statuslayout, null);                  textview statustext = (textview) statusupdateview.findviewbyid(r.id.statusedittext);                  string text[] = msg.split("\n");                  statustext.settext(text[0]+"\n"+text[1]+"\n"+text[2]+"\n"+text[3]);                  new alertdialog.builder(thisclasscontext).settitle("current status of tracker at: "+checkid).setview(statusupdateview)                  .setpositivebutton("ok", new dialoginterface.onclicklistener()                   {                                      @suppresslint("simpledateformat")                    public void onclick(dialoginterface dialog, int whichbutton)                     {                                          }                 }).show();             } 

i copy instance context onreceive(context context, intent intent) method thisclasscontext.but program crashed. wrong coding? used same coding @ other activities, fine. thanks

you cannot show alert directly broadcastreceiver because there no window of activity show dialog..to show alert must start activity in receiver , in activity can show alert.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -