AsyncTask and Contexts

后端 未结 5 1414
情书的邮戳
情书的邮戳 2020-12-28 16:59

So I\'m working out my first multi-threaded application using Android with the AsyncTask class. I\'m trying to use it to fire off a Geocoder in a second thread, then update

5条回答
  •  灰色年华
    2020-12-28 17:17

    If doesn't look like you are using the params. You could use that to pass in the Conetxt.

    public class GeoCode extends AsyncTask {
      @Override
      protected GeoThread doInBackground(Context... params) {
        List
    addresses = null; Geocoder geoCode = null; geoCode = new Geocoder(params[0]); //Expects at minimum Geocoder(Context context); addresses = geoCode.getFromLocation(GoldenHour.lat, GoldenHour.lng, 1); } }

    Then from within your activity:

    GeoCode myGeoCode = new GeoCode();
    myGeoCode.execute(this);
    

提交回复
热议问题