java - URLConnection receive wrong text from php server -
i have app has 4 activities.in first activity want request text website (php file). first time press button data works fine in next times press button, returns correct text concatenates previous text.see example:
first press: returns: "abc" second press: returns: "abcabc" (must return abc) third press: returns: "abcabcabc" (must return abc) .
- i clear text view each time.
- i close connection each time.
- i close
bufferedreader
each time. - i close.
activity1:
try{ url u = new url(uu); httpurlconnection con = (httpurlconnection) u.openconnection(proxy.no_proxy); con.setdooutput(true); con.setusecaches(false); printstream pr = new printstream(con.getoutputstream()); pr.print("code=3&arg1=" + str); bufferedreader br = new bufferedreader(new inputstreamreader(con.getinputstream(),"utf-8")); string l; while ((l=br.readline())!=null){ z = z + "\n" + l; } br.close(); pr.close(); con.disconnect(); runonuithread(new runnable() { @override public void run() { textview tx = (textview) findviewbyid(r.id.textview2); tx.setmovementmethod(new scrollingmovementmethod()); tx.settext(""); tx.settext(z); } }); } catch (final exception ex){ }
i don't see declared z
string, appending it.
you should either clear it, or use new string each request.
and use stringbuilder
. memory usage lower.
Comments
Post a Comment