Android 另一个WindowManager$badtokenexception异常

Android 另一个WindowManager$badtokenexception异常,android,android-alertdialog,Android,Android Alertdialog,我已经用AlertDialog查看了每个关于这个问题的帖子,但没有结果。有人看到这里有什么不对劲吗?我尝试了DialogFragment,但我是从PhoneStateListener执行此操作的,无法扩展任何其他内容。我没有空标记,因此getBaseContext正在工作。我相信 private void lookupCallerId(int cstate) { if(prefs.getIsDeactivated()) return; if(l

我已经用AlertDialog查看了每个关于这个问题的帖子,但没有结果。有人看到这里有什么不对劲吗?我尝试了DialogFragment,但我是从PhoneStateListener执行此操作的,无法扩展任何其他内容。我没有空标记,因此getBaseContext正在工作。我相信

    private void lookupCallerId(int cstate)
{
    if(prefs.getIsDeactivated())
        return;     

    if(lookupInProgress)
    {
        return;
    }

    //add popup box here for lookup question?

    PMLog.v(LOGTAG, "lookupCallerId() Start pop up box.");                  
    Context context = service.getBaseContext();                 
    if(cstate == TelephonyManager.CALL_STATE_RINGING) {

     AlertDialog.Builder builder = new AlertDialog.Builder(context);
     PMLog.v(LOGTAG, "lookupCallerId() ALERT BUILDER.");

     builder.setTitle("Lookup this #?");
     builder.setCancelable(true);
     builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

         public void onClick(DialogInterface dialog, int which) {
             String strPhoneNumber = PhoneNumberProcessor.formattedPhoneNumber(prefs.getLastCallerNumber(), service); {
                 if(strPhoneNumber.length() == 0)                    
                        return;
             }

             PMLog.v(LOGTAG, "lookupCallerId() Starting CNM lookup thread");
             Thread thread = new Thread(null, doBackgroundThreadProcessing, "LookupBackgroundThread");
             thread.start();
             }
         }
     );
     builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
            onNo();
             return;
         }
     });
     builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
         public void onCancel(DialogInterface dialog) {
             onNo();
             return;
         }
     });        
        builder.create().show();        
    }       
}

问题是由于
Context=service.getBaseContext()

UI元素只能通过活动上下文(即,和现有UI)添加。由于基本上下文没有关联的UI,因此不能使用它向UI添加任何内容


从活动中启动对话,或使用意图从服务中启动以对话为主题的活动。

谢谢。您能否提供一个链接,指向有关使用意图启动对话主题活动的信息?