在“onCreate”中,我正在从网络下载数据。下载数据的持续时间为 10 秒。下载数据时我不想有 ProgressDialog。这是我的代码,但 ProgressDialog 没有出现:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressDialog dialog = ProgressDialog.show(Test.this, "",
"Loading. Please wait...", true);
try {
URL myURL = new URL("http://www.sample.com/");
URLConnection ucon = myURL.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
content= new String(baf.toByteArray());
}
catch (Exception e) {}
dialog.dismiss();
}