title: Return LatLng object from nested asynctask
body: <p>I have spent days on this, but I can't find a solution to my problem:</p>
  
  <p>I'm developing an app that retrieves a list of theaters showing some movie selected by the user, parsing an HTML page in an AsyncTask.</p>
  
  <p>I want to visualize those theaters on a Map with markers, so I need coordinates: once the "GetCinemaList" AsyncTask is completed, I try to populate my markerList in onPostExecute.</p>
  
  <p>I have an SQLite db in which I store [theater|city|lat|lng]. So I first look up in the db, if it is not found I want call another AsyncTask to retrieve coordinates from HTTP google geocoding ('cause device geocoder returns null, causing the app to crash)</p>
  
  <p>The problem is I am not able to return the LatLng point to the first AsyncTask...</p>
  
  <p>I have tried to use listeners and to override processFinish(LatLng p), but I can't assign the value to my variable cause, accessing it from inner class it should be final.</p>
  
  <p>Any help/idea? Thanks!</p>
  
  <p>Here my code (containing error) for the AsyncTasks , in my Activity.</p>
  
  <pre><code>private class GetCinemaList extends AsyncTask&lt;URL, Void, List&lt;String&gt;&gt; {
      private Context mContext;
  
  
      public GetCinemaList(Context c){
          mContext = c;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected List&lt;String&gt; doInBackground(URL... urls) {
          List&lt;String&gt; cinemas = new ArrayList&lt;&gt;();
          Document docHTML = null;
          try {
              docHTML = QueryUtils.makeRequest(urls[0]);
              cinemas = QueryUtils.extractCinemasFromHTML(mTitile, docHTML);
          } catch (IOException e) {
              Log.e("JSwa", "Problem making request for parsing HTML "+e);
          }
  
          return cinemas;
      }
  
      @Override
      protected void onPostExecute(List&lt;String&gt; result) {
          super.onPostExecute(result);
          cinemaList = result;
          LatLng point;
  
          pointList = new ArrayList&lt;&gt;();
          for (String elem : cinemaList) {
              String name = elem.split("\t")[0];
              String orari = elem.split("\t")[1];
  
              Cursor cursor = queryDB(mCinemaDbR, city, name);
              if (!cursor.moveToFirst()) {
                  // call geocoding service
  
                  new LatLongFromService(name.concat(" " + city), new AsyncResponse() {
                      @Override
                      public void processFinish(LatLng output) {
                          point = output;
                      }
                  }).execute();
  
                  Log.d("JSwa", "Inserting point "+point.toString());
  
                  // insert new value in the database
                  long id = addCimena(mCinemaDbW, name, city, String.valueOf(point.latitude), String.valueOf(point.longitude));
                  // insert new value in the list
  
                  MarkerOptions marker = new MarkerOptions().position(point).title(name).snippet(orari);
                  pointList.add(marker);
              }
              else{
                  double lat = Double.parseDouble(cursor.getString(cursor.getColumnIndex(CinemaEntry.COLUMN_LAT)));
                  double lng = Double.parseDouble(cursor.getString(cursor.getColumnIndex(CinemaEntry.COLUMN_LNG)));
  
                  MarkerOptions marker = new MarkerOptions().position(new LatLng(lat,lng)).title(name)
                          .snippet(orari);
                  pointList.add(marker);
              }
              cursor.close();
          }
          for (MarkerOptions marker : pointList){
              m_map.addMarker(marker);
          }
  
      }
  }
  </code></pre>
  
  <p>// Sometimes happens that device gives location = null</p>
  
  <pre><code>public class LatLongFromService extends AsyncTask&lt;Void, Void, StringBuilder&gt; {
  
      String place;
      public AsyncResponse delegate = null;
  
      public LatLongFromService(String place, AsyncResponse resp) {
          this.place = place;
          delegate = resp;
      }
  
  
      @Override
      protected StringBuilder doInBackground(Void... params) {
  
          try {
              HttpURLConnection conn = null;
              StringBuilder jsonResults = new StringBuilder();
              String googleMapUrl = "http://maps.googleapis.com/maps/api/geocode/json?address=" + this.place + "&amp;sensor=false";
  
              URL url = new URL(googleMapUrl);
              conn = (HttpURLConnection) url.openConnection();
              InputStreamReader in = new InputStreamReader(
                      conn.getInputStream());
              int read;
              char[] buff = new char[1024];
              while ((read = in.read(buff)) != -1) {
                  jsonResults.append(buff, 0, read);
              }
              return jsonResults;
          } catch (Exception e) {
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(StringBuilder result) {
          super.onPostExecute(result);
          try {
              JSONObject jsonObj = new JSONObject(result.toString());
              JSONArray resultJsonArray = jsonObj.getJSONArray("results");
  
              JSONObject location = resultJsonArray
                      .getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
  
              String lat_helper = location.getString("lat");
              double lat = Double.valueOf(lat_helper);
  
  
              String lng_helper = location.getString("lng");
              double lng = Double.valueOf(lng_helper);
  
              delegate.processFinish(new LatLng(lat, lng));
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  }`
  </code></pre>