1

每当我使用 Geocode 类的反向地理编码来获取当前城市名称时,整个用户界面都会冻结片刻,直到返回响应。我该如何避免这个问题?

4

1 回答 1

3

您可能想使用AsyncTask

private void doGeoCode(Location loc){

 AsyncTask<Location,Void,String> task  = new AsyncTask<Location,Void,String>(){

   @Override
    protected String doInBackground(Location... args) {
      Location loc = args[0];
      String address = "Unknown";

      //--do geo code lookup--

      return address;
    }

    @Override
    protected void onPostExecute(String address){
      //--set some TextView's text etc.
    }

 };

  task.execute(loc);
}
于 2013-07-10T09:33:52.023 回答