可能重复:
ProgressDialog 未显示在活动中
在我的主类中,我调用 new AutoUpdate().checkForUpdate(this);
这是动作
public void checkForUpdate(Context context) {
// check when last checked. unless overridden check once a day.
// get current version
int resID = context.getResources().getIdentifier("current_version",
"string", context.getPackageName());
currentVersion = context.getResources().getString(resID);
// check for connection
// now compare versions
if (currentVersion.equals(serverVersion) == false) {
ProgressDialog pDialog = new ProgressDialog(context);
pDialog.setMessage("DO NOT ROTATE YOUR DEVICE. /nI am upgrading your version, press OK then INSTALL in a minute. Please wait....");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
try {
URL url = new URL(prefs.getString("server_address", null)
+ "/updates/eduDroid.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
String PATH = Environment.getExternalStorageDirectory()
+ "/download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "eduDroid.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory()
+ "/download/"
+ "file.apk")),
"application/vnd.android.package-archive");
context.startActivity(intent);
} catch (IOException e) {
Toast.makeText(context, "Update error!", Toast.LENGTH_LONG)
.show();
}
pDialog.dismiss();
}
}
问题是下载更新版本需要很长时间。在那段时间里,用户留下一个空白屏幕。我想向他们展示对话框,但它只是没有显示。请帮忙