【发布时间】:2015-03-16 15:18:46
【问题描述】:
我在测试我的应用时遇到问题:它从互联网加载数据并将其输出到屏幕上。当我尝试用模拟器测试它时 - 下载开始,但没有完成。当我用普通智能手机尝试时 - 一切正常,数据在一秒钟内加载。这是一个代码,但我认为问题不在于它:
final Button butTest = (Button)findViewById(R.id.parse);
final TextView tvInfo = (TextView)findViewById(R.id.getdata);
butTest.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
(new AsyncLoad()).execute("http://yandex.ru");
}
class AsyncLoad extends AsyncTask<String, Void, String> {
Document doc = null;
private ProgressDialog mProgressDialog;
@Override
protected String doInBackground(String... params) {
publishProgress(new Void[] {});
try {
doc = Jsoup.connect(params[0]).get();
} catch (IOException e) {
e.printStackTrace();
}
return doc.title();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(GetData.this);
mProgressDialog
.setMessage("Download...");
mProgressDialog.show();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
tvInfo.setText(result);
mProgressDialog.dismiss();
}
}
});
我在 Eclipse 中工作,这些是模拟器设置:RAM 1024、内部存储 200、VM 堆 64。它在其他测试中运行不那么快,但仍然可以运行。使用此代码,我可以等待 10、15、20 分钟 - 它会继续执行 PreExecute(),但不会更久。
【问题讨论】:
-
你试过关闭你的模拟器,然后重新启动它
-
如果你认为你的问题是模拟器,你能告诉我们它的细节吗?
-
感谢您的回答,我编辑了第一篇文章。