调用 MainActivity 时,我正在制作加载效果。我不知道为什么我的 Dialog.show 不能在 AsyncTask 中工作。我只看到它关闭的那一刻,但在此之前从未出现过对话框。谢谢你。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new LoadViewTask().execute();
setContentView(R.layout.activity_main);
....}
private class LoadViewTask extends AsyncTask<Void, Integer, Void>
{
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(MainActivity.this,"Loading...","Loading application View, please wait...", false, false);
}
@Override
protected Void doInBackground(Void... params)
{
try
{
synchronized (this)
{
int counter = 0;
while(counter <= 4)
{
this.wait(1000);
counter++;
publishProgress(counter*25);
}
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values)
{
progressDialog.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void result)
{
progressDialog.dismiss();
}
}