2013-02-05 3 views
0

android.app.ProgressDialog 처리시 android.os.AsyncTask 접근 방식에 익숙하지 않습니다. android.database.Cursor을 통해 특정 쿼리를 처리하고 필요한 엔티티로 변환하는 문제가 있습니다.Android ProgressDialog 쿼리 처리

이 템플릿을 따르고 있지만 항상 android.view.WindowManager$BadTokenException을 반환합니다.

List<Entity> loadData() throws Exception { 
    AsyncTask<Cursor, Void, List<Entity>> process = new AsyncTask<Cursor, Void, List<Entity>>() { 
     ProgressDialog dialog; 
     protected void onPreExecute() { 
      dialog = ProgressDialog.show(getApplicationContext(), "Please wait...", "Loading data...");   
     } 
     protected void onPostExcecute() { 
      dialog.dismiss(); 
     } 
     @Override 
     protected List<Entity> doInBackground(Cursor... params) { 
      List<Entity> entities = new ArrayList<Entity>(); 
      // process of convertion of data from android.database.Cursor to <pacakge>.Entity 
      return entities; 
     } 
    }.execute(/* the query : android.database.Cursor */) 
    return process.get(); 
} 

내가 누락 된 것이 있습니까? Activity에서 별도의 클래스에서 실행되는

dialog = ProgressDialog.show(Your_Current_Activity.this, 
        "Please wait...", 
        "Loading data..."); 

AsyncTask 경우 다음 현재 활동을 통과해야합니다

답변

1

AsyncTask를 같이 getApplicationContext() 대신에 실행되고있는 현재 활동 컨텍스트를 사용 AsyncTask를의 onPreExecute() 방법에서 ProgressDialog를 표시합니다 AsyncTask의 클래스 생성자를 사용하는 AsyncTask의 컨텍스트

+0

ProgressDialog가 나타나지 않거나 프로세스가 끝날 때 나타나지 않습니다. –

+0

@ Dr.Java : doInBackground 실행이 완료되지 않을 때까지 UI를 고정시키는 AsyncTask의 get 메소드를 사용 중이므로 오류가 아닙니다. –

+0

어떻게 해결할 수 있을지에 대한 제안이 있으십니까? –