Issue
I have in my app data retrieval by using http GET method. Once the task finishes, i wish to display the return vlaue in my mainActivity (I have just 1 activity in my app at the moment)
This is my asyncTask class:
class getAsync extends AsyncTask<String,Void,String> {
String ret;
@Override
protected String doInBackground(String... params) {
String url = params[0];
myGetReq myget = new myGetReq();
ret = myget.get(url);
Log.d("[RETURN STATUS]",ret);
return ret;
}
}
and from my main activity, i use it in the following way:
getAsync get = new getAsync();
get.execute(url);
statText.setText(get.ret);
where statText is a text in my activity window. It stays blank, even tough I can see in logcat the body of the response. How to I deliver this data back, properly, to my activity?
Solution
Asynce Task have onPostExecute Method... In this method you can work on UI componetnt so i have settext in onPostExecute ... use below code..
class getAsync extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... params) {
String url = params[0];
myGetReq myget = new myGetReq();
String ret = myget.get(url);
Log.d("[RETURN STATUS]",ret);
return ret;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
statText.setText(result);
}
}
Answered By - Sanket Kachhela
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.