我正在使用Facebook SDK将照片上传到Facebook。当照片上传时,我想显示一个进度对话框,我面临一个奇怪的问题。
当我在ProgressDialog
方法中声明onPreExecute()
时,会显示对话框。
protected void onPreExecute() {
super.onPreExecute();
ProgressDialog dialog = new ProgressDialog(Second.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(true);
dialog.setMessage("Uploading...");
dialog.show();
}
但是当我在全球宣布它时,没有任何事情发生。
class newPhotoUpload extends AsyncTask<Void, Void, Void> {
ProgressDialog dialog = new ProgressDialog(Second.this);
Intent viewIntent;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(true);
dialog.setMessage("Uploading...");
dialog.show();
}
为什么会这样?
答案 0 :(得分:2)
将进度条设为全局变量(MainActivity extends Activity
下方),例如
ProgressDialog dialog=null;
然后
class newPhotoUpload extends AsyncTask<Void, Void, Void> {
Intent viewIntent;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(Second.this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(true);
dialog.setMessage("Uploading...");
dialog.show();
}