Android 最新的值似乎没有得到更新。只有当我关闭并重新打开应用程序时,我才能看到显示的最新值。
该应用程序的基本功能是从FTP服务器中的.csv文件(注意:服务器上的.csv文件)获取实时数据 保持从另一个源同时更新。),并在图形上显示值 我能够成功地连接到FTP服务器并解析.csv文件,并在图形上显示所有记录的值。但是,最新的值似乎没有在图表上得到更新。只有当我关闭并重新打开应用程序时,我才能看到图表上显示的最新值 我尝试了以下代码但未成功:Android 最新的值似乎没有得到更新。只有当我关闭并重新打开应用程序时,我才能看到显示的最新值。,android,csv,ftp,real-time-updates,Android,Csv,Ftp,Real Time Updates,该应用程序的基本功能是从FTP服务器中的.csv文件(注意:服务器上的.csv文件)获取实时数据 保持从另一个源同时更新。),并在图形上显示值 我能够成功地连接到FTP服务器并解析.csv文件,并在图形上显示所有记录的值。但是,最新的值似乎没有在图表上得到更新。只有当我关闭并重新打开应用程序时,我才能看到图表上显示的最新值 我尝试了以下代码但未成功: /* * Connects to a remote FTP server */ void connectToFTP() {
/*
* Connects to a remote FTP server
*/
void connectToFTP() {
try {
mFTPClient = new FTPClient();
mFTPClient.connect(FTP_HOSTNAME, FTP_PORT);
returnCode = mFTPClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(returnCode)) {
throw new IOException("Could not connect");
}
boolean loggedIn = mFTPClient.login(FTP_USER, FTP_PASSWORD);
if (!loggedIn) {
throw new IOException("Could not login");
}
System.out.println("Connected and Logged in");
statusUpdate.setText("Connected to FTP Server");
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
} catch (Exception e) {
e.printStackTrace();
}
}
void beginListenForData() throws IOException {
final Handler handler = new Handler();
final byte delimiter = 10; //This is the ASCII code for a newline character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
mmInputStream = mFTPClient.retrieveFileStream(fileName);
workerThread = new Thread(new Runnable() {
public void run() {
while (!Thread.currentThread().isInterrupted() && !stopWorker) {
try {
Log.i("Inside begindata ", "data " + count++);
int bytesAvailable = mmInputStream.available();
if (bytesAvailable > 0) {
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for (int i = 0; i < bytesAvailable; i++) {
byte b = packetBytes[i];
if (b == delimiter) {
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");
readBufferPosition = 0;
handler.post(new Runnable() {
public void run() {
myLabel.setText(data);
String s = data;
String[] values = data.split(",");
Log.i("Text ", "data " + values[3]);
datalist.add(values[3]);
power.setText(values[3]);
}
});
} else {
readBuffer[readBufferPosition++] = b;
}
}
// dataPoints();
}
} catch (IOException ex) {
stopWorker = true;
}
}
}
});
workerThread.start();
}
/*
*连接到远程FTP服务器
*/
void connectToFTP(){
试一试{
mFTPClient=新的FTPClient();
连接(FTP\主机名、FTP\端口);
returnCode=mFTPClient.getReplyCode();
如果(!FTPReply.isPositiveCompletion(返回代码)){
抛出新IOException(“无法连接”);
}
boolean loggedIn=mFTPClient.login(FTP_用户,FTP_密码);
如果(!loggedIn){
抛出新IOException(“无法登录”);
}
System.out.println(“已连接并已登录”);
statusUpdate.setText(“连接到FTP服务器”);
mFTPClient.setFileType(FTP.BINARY\u文件类型);
mFTPClient.enterLocalPassiveMode();
}捕获(例外e){
e、 printStackTrace();
}
}
void beginListenForData()引发IOException{
最终处理程序=新处理程序();
final byte delimiter=10;//这是换行符的ASCII码
stopWorker=false;
readBufferPosition=0;
readBuffer=新字节[1024];
mmInputStream=mFTPClient.retrieveFileStream(文件名);
workerThread=新线程(new Runnable()){
公开募捐{
而(!Thread.currentThread().isInterrupted()&&!stopWorker){
试一试{
Log.i(“内部begindata”,“数据”+计数+);
int bytesavable=mmInputStream.available();
如果(字节可用>0){
byte[]packetBytes=新字节[bytesAvailable];
mmInputStream.read(packetBytes);
for(int i=0;i
使用Async task从服务器下载数据,并在onPostExecute方法中更新UI
从活动的“onCreate”方法启动此异步任务。将解析的值存储在SQLite DB中,并使用内容提供程序刷新数据。我对android和SQLite不熟悉。你能举个例子吗?我是android新手。你能举个例子吗?