Source:
protected Integer doInBackground(Location... locate) { Location location = locate[0]; Activity context = contextRef.get(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int limit = Integer.parseInt(sp.getString("nearbyStopsCount", "20")); String signature = ValidationHelper.getSignatureForValidation(context); String url = "<LINK_0>" + location.getLatitude() + "," + location.getLongitude() + "&limit=" + limit; LogHelper.d("CURRENT-LOCATION", url); url += "&sig=" + signature + "&package=" + context.getPackageName(); String tmp; try { URLHelper urlHelper = new URLHelper(url); tmp = urlHelper.executeString(); } catch (IOException e) { except = e; return 1; } Gson gson = new Gson(); LogHelper.d("CURRENT-LOCATION", tmp); if (!StaticVariables.INSTANCE.checkIfYouGotJsonString(tmp)) { except = new Exception(context.getResources().getString(R.string.toast_message_invalid_json)); return 2; } Distance distArray = gson.fromJson(tmp, Distance.class); if (distArray == null || distArray.getResults() == null) { except = new Exception("Invalid Distance retrieved from API. Please try again later"); return 3; } Distance.DistanceItem[] results = distArray.getResults(); ArrayList<BusStopJSON> stops = new ArrayList<>(); assert results != null; for (Distance.DistanceItem map : results) { float distance = map.getDist(); BusStopJSON stop = db.getBusStopByBusStopCode(map.getBusStopCode()); stop.setDistance(distance * 1000); stop.setHasDistance(true); stops.add(stop); } Intent sendForMapParsingIntent = new Intent(BusStopNearbyFragment.RECEIVE_NEARBY_STOPS_EVENT); Type listType = new TypeToken<ArrayList<BusStopJSON>>() {}.getType(); sendForMapParsingIntent.putExtra("data", gson.toJson(stops, listType)); context.runOnUiThread(() -> { LocalBroadcastManager.getInstance(context).sendBroadcast(sendForMapParsingIntent); adapter.updateAdapter(stops); adapter.notifyDataSetChanged(); }); return 0; }

Target:
protected Integer doInBackground(Location... locate) { Location location = locate[0]; Activity context = contextRef.get(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); int limit = Integer.parseInt(sp.getString("nearbyStopsCount", "20")); String signature = ValidationHelper.getSignatureForValidation(context); String url = "<LINK_0>" + location.getLatitude() + "," + location.getLongitude() + "&limit=" + limit; LogHelper.d(TAG, url); url += "&sig=" + signature + "&package=" + context.getPackageName(); String tmp; try { URLHelper urlHelper = new URLHelper(url); tmp = urlHelper.executeString(); } catch (IOException e) { except = e; return 1; } Gson gson = new Gson(); LogHelper.d(TAG, tmp); if (!StaticVariables.INSTANCE.checkIfYouGotJsonString(tmp)) { except = new Exception(context.getResources().getString(R.string.toast_message_invalid_json)); return 2; } Distance distArray = gson.fromJson(tmp, Distance.class); if (distArray == null || distArray.getResults() == null) { except = new Exception("Invalid Distance retrieved from API. Please try again later"); return 3; } Distance.DistanceItem[] results = distArray.getResults(); ArrayList<BusStopJSON> stops = new ArrayList<>(); assert results != null; for (Distance.DistanceItem map : results) { float distance = map.getDist(); BusStopJSON stop = db.getBusStopByBusStopCode(map.getBusStopCode()); stop.setDistance(distance * 1000); stop.setHasDistance(true); stops.add(stop); } Intent sendForMapParsingIntent = new Intent(BusStopNearbyFragment.RECEIVE_NEARBY_STOPS_EVENT); Type listType = new TypeToken<ArrayList<BusStopJSON>>() {}.getType(); sendForMapParsingIntent.putExtra("data", gson.toJson(stops, listType)); context.runOnUiThread(() -> { LocalBroadcastManager.getInstance(context).sendBroadcast(sendForMapParsingIntent); adapter.updateAdapter(stops); adapter.notifyDataSetChanged(); }); return 0; }