2013-11-20 6 views
0

AsyncTask에서 대화 상자를 표시하는 방법. dialog.show()에서 BadToketException을 얻는 중. 여러 가지 방법을 시도했지만 해결할 수 없었습니다.

다른 방법으로 대화 상자에 컨텍스트를 전달하려고 시도했지만 동일한 결과가 나타납니다.

public class RetriveStock extends AsyncTask<Void, Void, Void> { 

    @Override 
    protected Void doInBackground(Void... params) { 
     message = client.clientReceive(1); // I get data here. 

     return null; 
    } 

    @Override 
    protected void onCancelled() { 
     super.onCancelled(); 
    } 

    @Override 
    protected void onPostExecute(Void result) { 

     if (message.contains("AlertExecuted:")) { 
       final Dialog dialog = new Dialog(CreateAlert.this); 
       dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
       dialog.setContentView(R.layout.display_dialog);// Dialog layout 
       TextView dialogText = (TextView) dialog.findViewById(R.id.digMsg); 

       dialogText.setText("Alert Executed!"); 
       Button ok = (Button) dialog.findViewById(R.id.ok); 

       ok.setOnClickListener(new View.OnClickListener() { 

        @Override 
        public void onClick(View v) { 
         dialog.dismiss(); 
        } 
       }); 
       try { 
        dialog.show(); //WindowManager$BadTokenException 
       } catch (Exception e) { 

        e.printStackTrace(); 
       } 

     } 
     super.onPostExecute(result); 

    } 

    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
    } 

    @Override 
    protected void onProgressUpdate(Void... values) { 
     super.onProgressUpdate(values); 
    } 

} 

도와주세요. 사전 실행하고 onpostexecute에 정지에서

답변

0
protected void onPreExecute() { 
     // TODO Auto-generated method stub 



     //   progressDialog = ProgressDialog.show(this, "", "loading news content"); 
     progressDialog = new ProgressDialog(context , AlertDialog.THEME_HOLO_LIGHT); 
     progressDialog.setMessage(""+getString(R.string.laodnews)); 
     progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.animate)); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 

}

시작 dailoge ..

+0

을 통과하지 다음 manifest..if에서 CreateAlert 등록 활동 u는 제안했지만 동일한 예외가 발생했습니다. – user2085965

0

는 등록 활동 상황을 내가 노력

+0

예, 매니페스트에 등록 된 활동입니다. 당신은 등록 된 활동이이 권리라는 것을 의미합니다. user2085965

+0

RetriveStock이 동일한 CreateAlert 클래스에있는 경우 클래스 외부에있는 경우 코드에 아무런 문제가없는 경우 CreateAlert 활동 패스를 전달해야합니다. – Pavan

+0

RetriveStock이 내부에 있는지 확인하십시오. CreateAlert 클래스 만. – user2085965

관련 문제