开发者

sending values from android to server

I want to set the following code in a start and stop button to send my values to server after every second . so i am wondering how to adopt best strategy for it .should i put in a thread or refresh the activity . please guide me the easy direction to adopt . Thanks

URL url = n开发者_StackOverflowew URL("http://............./add.jsp?a="+value+"&b="+value+"");

URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
String line = null;
String response = "";
while ((line = rd.readLine()) != null) {
    response += line;                          
}

wr.close();
rd.close();


Maybe you will want to you an AsyncTask for that, calling this task frequently via a Timer. Or without AsyncTask and just the Timer. http://developer.android.com/reference/android/os/AsyncTask.html http://developer.android.com/reference/java/util/Timer.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜