비슷한 문제가 있음을 알고 있지만 여전히 답변을 찾지 못했습니다. 문제는이 긴 작업에 대한 진행 대화 상자가 표시되지 않지만 여전히 프로세스가 완료되고 있다는 것입니다. 컨텍스트에 문제가 있다고 생각하지만이 문제를 해결하는 방법은 없습니다.AsyncTask의 진행 대화 상자가 표시되지 않습니다.
public class MainActivity extends Activity {
Utilities uti = new Utilities();
SharedPreferences prefs = null;
private ContactServiceActivity contactService;
ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contactService = new ContactServiceActivity(getApplicationContext());
doFirstRun();
Intent i = new Intent(getBaseContext(), ContactListActivity.class);
startActivity(i);
}
private void doFirstRun() {
SharedPreferences settings = getSharedPreferences("pl.stxnext.stxcontactsync", MODE_PRIVATE);
if (settings.getBoolean("isFirstRun", true)) {
new firstRunTask().execute();
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("isFirstRun", false);
editor.commit();
}
}
private class firstRunTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setTitle("Trwa synchronizacja danych");
mProgressDialog.setMessage("Może to zająć chwilę, proszę czekać.");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
contactService.getAssetsAtFirstRun();
return null;
}
@Override
protected void onPostExecute(Void result) {
mProgressDialog.dismiss();
uti.showToast(getBaseContext(), "Zapisano kontakty.");
}
}
}
는 this..http 시도 마십시오 여전히 //stackoverflow.com/questions/17585759/cant-dismiss-progressdialog-after-the-asynctask-complete/17585792#17585792 – TheFlash