I need to get information from a web REST server and because I cant call over network from the main thread I did it with AsyncTask. I dont want to change the UI from the doPostExecute because I dont know which activity will call my class for information so I cant know what to change. I need to understand how I can send a request and get the information back to use it in my java class of the activity.
Asked
Active
Viewed 47 times
0
-
use a `callback`. users of your class pass a callback reference to you and then you call that on doPostExecute. – muratgu Feb 08 '16 at 22:26
-
Can you add an example? I tried to use a callback like this: MyAsyncTask asyncTask = (MyAsyncTask) new MyAsyncTask(new MyAsyncTask.AsyncResponse(){ @Override public void processFinish(JSONArray output){ arr[0] = output; } }).execute(URL + Repositories.get(repository) + data); – Yonatan Kreiner Feb 09 '16 at 00:30
-
see http://stackoverflow.com/questions/9963691/android-asynctask-sending-callbacks-to-ui – muratgu Feb 09 '16 at 00:54
-
I saw that and I took my code from that comment but still I cant use the response out of the delegate's block – Yonatan Kreiner Feb 09 '16 at 01:26
-
you need to update your question with what you have tried, what is working, what is not working, etc. so that people can help you. – muratgu Feb 09 '16 at 01:45