我正在使用 asyncTask 显示对话框,然后在几分钟后启动一个新活动。
不幸的是,该活动在任务完成之前开始???
package com.android.grad;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.Toast;
public class LoginTask extends AsyncTask<Void, Void, Boolean> {
private Activity activity;
private ProgressDialog pd;
public LoginTask(Activity activity) {
this.activity = activity;
}
@Override
protected void onPreExecute() {
pd = ProgressDialog.show(activity, "Signing in",
"Please wait while we are signing you in..");
}
@Override
protected Boolean doInBackground(Void... arg0) {
try {
Thread.sleep(10000000);
} catch (InterruptedException e) {
}
pd.dismiss();
return true;
}
@Override
protected void onPostExecute(Boolean result) {
Toast.makeText(activity, Boolean.toString(result), Toast.LENGTH_LONG).show();
}
}
我从按钮单击侦听器执行任务:S
private OnClickListener loginOnClick = new OnClickListener() {
public void onClick(View v) {
new LoginTask(LoginActivity.this).execute();
startActivity(new Intent(LoginActivity.this, BuiltInCamera.class));
}
};
有没有办法从我的子类 ofAsyncTask 开始活动。