我想在后台执行一些指令时显示一个进度条,但我不想锁定屏幕。此代码正在锁定屏幕:
private class ConvertDataInBackground extends AsyncTask<Params, Void, Boolean> {
private MyProgressDialog mProgressDialog;
@Override
public void onPreExecute() {
if(mProgressDialog == null)
mProgressDialog = MyProgressDialog.show(mActivity, null, null);
}
@Override
protected Boolean doInBackground(Params...params) {
boolean conversionResult = executeConversion(params[0].item1, params[0].item2, params[0].item3);
return conversionResult;
}
@Override
protected void onPostExecute(Boolean result) {
try {
if(mProgressDialog.isShowing())
mProgressDialog.dismiss();
if(result) {
Toast toast = Toast.makeText(mActivity, R.string.conversion_result, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
在后台执行指令可能需要一段时间,我希望用户能够使用界面。你是否知道我们可以使用界面,而progressDialog 显示在顶部?