Reputation: 1400
How to Store and Use HttpResponse in variable from AsyncTask into MainActivity?
Upvotes: 0
Views: 218
Reputation: 602
Add Post execute method in your async task
@Override
protected void onPostExecute(String result) {
Log.d("RESULT", "Result : " + result);
finalResult = result; // here finalResult is string variable declared at class level
}
Add one other method that is return final result of async task.
public String getFinalResult() {
return finalResult;
}
When you need final result you can use getFinalResult method to get.
Upvotes: 0
Reputation: 316
You should use the 'onPostExecute' callback to receive the async result of your doInBackground.
Read here for info: https://developer.android.com/reference/android/os/AsyncTask.html
The onPostExecute runs on the UI thread so it can interact with your UI elements, such as your buttons and EditText.
Upvotes: 1