私はonCreate
メソッドで実行されるAsyncTaskを持っています。しかし、私のProgressDialogは表示されません。そして、デバッグからAsyncTaskが実行されていることが確認されます。Android:ProgressDialogがonCreate()で呼び出されたAsyncTaskに表示されない
@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このコードを試してください –
これはうまくいきます。どこが間違っていたのか分かりませんが、感謝です問題が解決した場合は –
に印を付けてください。 –