更新时间:2023-01-25 18:08:41
我有同样的问题,使用的 AsyncTask的是为我工作。
I had the same issue and using an AsyncTask is working for me.
有在AsyncTask的覆盖三个重要的方法。
There are 3 important methods to override in AsyncTask.
如果你让你的AsyncTask子类作为一个内部类的活动,那么你可以从你的AsyncActivity中调用框架方法的ShowDialog,dismissDialog和removeDialog。
If you make your AsyncTask subclass as an inner class of your activity, then you can call the framework methods showDialog, dismissDialog, and removeDialog from within your AsyncActivity.
下面是AsyncTask的样本实现:
Here's a sample implementation of AsyncTask:
class LoginProgressTask extends AsyncTask<String, Integer, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
try {
Thread.sleep(4000); // Do your real work here
} catch (InterruptedException e) {
e.printStackTrace();
}
return Boolean.TRUE; // Return your real result here
}
@Override
protected void onPreExecute() {
showDialog(AUTHORIZING_DIALOG);
}
@Override
protected void onPostExecute(Boolean result) {
// result is the value returned from doInBackground
removeDialog(AUTHORIZING_DIALOG);
Intent i = new Intent(HelloAndroid.this, LandingActivity.class);
startActivity(i);
}
}