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) . 
  1. i clear text view each time.
  2. i close connection each time.
  3. i close bufferedreader each time.
  4. 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

Popular posts from this blog

Sass watch command compiles .scss files before full sftp upload -

filehandler - java open files not cleaned, even when the process is killed -

gridview - Yii2 DataPorivider $totalSum for a column -