2012-07-20 7 views
1

내 코드가 작동하지 않는 이유를 모르겠습니다. 나는 많은 동일한 문제를 읽었지 만, 이것은 대부분의 경우 올바른 해결책이지만, 나를 위해 일하는 것이 아닙니다.Dismiss() 메소드로 ProgressDialog를 멈출 수 없습니다.

public class SavingAsync extends AsyncTask<String, String, String> { 
private static final String TAG = "DrawView"; 
private ProgressDialog pd; 
private Context context; 
private File saveFile; 
private Bitmap bitmap; 

public SavingAsync(Context c, File sF, Bitmap b) { 
    context = c; 
    saveFile = sF; 
    bitmap = b; 
} 

@Override 
protected void onPostExecute(String result) { 
    pd.dismiss(); 
    super.onPostExecute(result); 
} 

@Override 
protected void onPreExecute() { 
    pd = new ProgressDialog(context); 
    ProgressDialog.show(context, "", "Saving..."); 
    super.onPreExecute(); 
} 

@Override 
protected String doInBackground(String... params) { 
    OutputStream stream; 
    try { 
     stream = new FileOutputStream(saveFile); 
     bitmap.compress(CompressFormat.PNG, 80, stream); 
     stream.close(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 

}

비트 맵이 성공적으로 저장되지만해서 ProgressDialog 영원히 실행 : 내 AsyncTask를은 다음과 같습니다/

+0

체크 아웃 http://developer.android.com/reference/android/app/DialogFragment.html –

답변

3

을 방법은를 반환 당신은

ProgressDialog.show(context, "", "Saving..."); 

와 쇼 ProgressDiaog을 보여주고있다 PreogressDialog 객체.

pd pd를 사용하여 참조 변수를 사용하여 해고 할 대화 상자. dismiss() 코드에 표시되는 대화 상자에 대한 참조가 있습니다. pd에 할당해야합니다. 이

pd = ProgressDialog.show(context, "", "Saving..."); 

그리고 pd.dismiss()를 호출하면 해고 것처럼 현재 Dialog을 표시합니다.

+1

오! 부끄러운 줄 알아 ... 고마워! – west44

+0

네, 걱정하지 마십시오 ... 질문 후 10 분이 지나면 작동합니다. – west44

관련 문제