我想从网站获取html数据,现在我只是简单地将textview更改为网页标题。出于某种原因,此文本视图只在我退出应用程序并重新打开时显示标题。我猜这是由于线程和我不知道的东西。作为一个例子,这里是我的stackoverflow.com网站代码:线程不启动,直到应用程序在Android上重新启动
public void onResume() {
super.onResume();
Thread downloadThread = new Thread() {
public void run() {
Document doc;
try {
doc = Jsoup.connect("http://www.stackoverflow.com").get();
titlestring = doc.title();
} catch (IOException e) {
e.printStackTrace();
}
}
};
downloadThread.start();
TextView maintext = (TextView) findViewById(R.id.maintext);
Log.i("wbbug", "Title string: " + titlestring);
maintext.setText(titlestring);
}
出于某种原因,它不显示网页的标题,直到我启动应用程序,按home,然后重新打开它。为什么是这样?
检查活动的生命周期。 http://developer.android.com/training/basics/activity-lifecycle/index.html – Raghunandan