我很难理解每次启动应用程序时 Android 应用程序如何获取数据或刷新数据。
我有数据,它每分钟更新一次,这意味着它会发生变化,但每次启动应用程序时我都看不到它更新,只是随机更新数据。
我累了,还是不行。
OnResume();
这是我的代码。
package com.zv.android;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ZipActivity extends Activity {
TextView textMsg, textPrompt;
final String textSource = "https://docs.google.com/spreadsheet/pub?key=0AqSBI1OogE84dDJyN0tyNHJENkNyYUgyczVLX0RMY3c&single=true&gid=0&range=a2%3Aa26&output=txt";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textPrompt = (TextView)findViewById(R.id.textprompt);
textMsg = (TextView)findViewById(R.id.textmsg);
textPrompt.setText("Wait...");
URL CPE;
try {
CPE = new URL(textSource);
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(CPE.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer + "\n"; ;
}
bufferReader.close();
textMsg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
textMsg.setText(e.toString());
}
textPrompt.setText("Finished!");
}
}