Ich habe eine AsyncTask, die in der onCreate
Methode ausgeführt wird. Mein ProgressDialog wird jedoch nicht angezeigt. Und vom Debuggen wird bestätigt, dass die AsyncTask ausgeführt wird.Android: ProgressDialog nicht in AsyncTask aufgerufen in OnCreate() aufgerufen
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lifestyle);
context = getApplicationContext();
new testAsync().execute();
}
private class testAsync extends AsyncTask<Void,Void,Void> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this); // tried with context, no difference
pDialog.setTitle("Inserting sample data");
pDialog.setMessage("Please wait. This dialog will be dismissed upon completion.");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// TableControllerReadings TCR = new TableControllerReadings(context);
// TCR.insertSampleData(getApplicationContext());
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//delay for 5 seconds
}
}, 5000);
return null;
}
@Override
protected void onPostExecute(Void v) {
pDialog.dismiss();
}
}
kai versuchen Sie diesen Code –
Okay, das funktioniert gut. Nicht sicher, wo schief gelaufen ist, aber danke! –
Wenn Ihr Problem beheben Sie bitte Häkchen. –