I have Activity and Service, which is called by bindService from Activity. In this service I perform some operations in another thread using Vk sdk. Here I parse json to my models and add them to list. My question is how can I send this list from another thread after parsing to my activity? Here is code of my service
public class RequestService extends Service {
private final IBinder mBinder = new RequestBinder();
private List<Item> mItems;
private String mStartFrom;
private VKRequest mVKRequest;
public class RequestBinder extends Binder {
public RequestService getService() {
return RequestService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
mItems = new ArrayList<>();
loadNews("");
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public void loadNews(String startFrom) {
if (startFrom.equals("")) {
mItems.clear();
}
mVKRequest = new VKRequest(Constants.METHOD_NAME, VKParameters.from(Constants.FILTERS,
Constants.FILTER_NAMES, VKApiConst.COUNT, Constants.NEWS_COUNT, Constants.START_FROM,
startFrom));
// this performs in another thread
mVKRequest.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
super.onComplete(response);
JSONObject result = response.json;
try {
mItems = ParseUtils.parse(result);
mStartFrom = ParseUtils.getNextFrom();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
public List<Item> getItems() {
return mItems;
}
public String getStartFrom() {
return mStartFrom;
}
}