java - Save output into two variables in Android from HTTP call -


i saw few posts (like one: android httppost: how result) of answers deprecated in mid 2016 latest android , don't answer full question.

i'm having app http call (http://52.35.9.101:8080/server/keeper/login_test.jsp?username=[uniquexx]), this:

new httprequest().execute("http://52.35.9.101:8080/server/keeper/login_test.jsp?username=[uniquexx]"); intent intent = new intent(getactivity(), mainactivity.class); startactivity(intent); 

which passes async java file called http request:

public class httprequest extends asynctask<string, string, string> {  @override protected string doinbackground(string... uri) {     httpclient httpclient = new defaulthttpclient();     httpresponse response;     string responsestring = null;     try {         response = httpclient.execute(new httpget(uri[0]));         statusline statusline = response.getstatusline();         if(statusline.getstatuscode() == httpstatus.sc_ok){             bytearrayoutputstream out = new bytearrayoutputstream();             response.getentity().writeto(out);             responsestring = out.tostring();             out.close();         } else{             //closes connection.             response.getentity().getcontent().close();             throw new ioexception(statusline.getreasonphrase());         }     } catch (clientprotocolexception e) {         //todo handle problems..     } catch (ioexception e) {         //todo handle problems..     }     return responsestring; }  @override protected void onpostexecute(string result) {     super.onpostexecute(result);     //do response.. } } 

if put http call browser you'll see server responds following string (two unique id's, separated comma need parse , save 2 separate variables)

5467326,8674922

my question how save output string (which seem doing above) , parse string 2 separate variables (x & y).

edit -----

@override  protected void onpostexecute(string result) { super.onpostexecute(result); string x = null; string y = null; string[] resultitems = result.split(","); log.d("tag_name", "result " +resultitems); x = resultitems[0]; log.d("tag_name", " xxxxx " +x); y = resultitems[1]; log.d("tag_name", " yyyyy " +y); 

in onpostexecute - value of result (in example), "5467326,8674922" if went - in case. how can split , parse response

protected void onpostexecute(string result) {     super.onpostexecute(result);     //do response..     string x = null;     string y = null;     string[] resultitems = result.split(",");     x = resultitems[0];     y = resultitems[1];    //now whatever x , y...  } 

i hope helps you.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo