代码如下:
public class Location extends AsyncTask<String, Integer, String> {
// public static final String TAG = UpdateTask.class.getSimpleName();
ProgressDialog pDialog;
private Context context;
public ProgressDialog pBar;
public TextView addrs;
public String s = null; public Location(Context context) {

this.context = context;
pDialog = new ProgressDialog(context);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setTitle("提示");
pDialog.setMessage("正在定位、请稍后...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();

} @Override
protected String doInBackground(String... params) {
if (mylocation != null)
mylocation.requestLocation();
// 发起定位
option = new LocationClientOption();
option.setCoorType("bd09ll");
option.setScanSpan(1000*4);
option.setPriority(LocationClientOption.NetWorkFirst);// 设置网络模式优先
// option.setOpenGps(true); mylocation.setLocOption(option);
mylocation.start();
String content = null;
String uri = Config.BASE_URL + "shouji/getQuyuCode.action";
String parameters = "quyuname=" + addr.getText();
//存储定位位置
SharedPreferences sp = getSharedPreferences(Config.PREFS_NAME,
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(Config.PREFS_QUYU_NAME,addr.getText().toString());
editor.commit();
try {
content = HttpHelper.downloadContent(uri, parameters,
HttpHelper.ContentType.JSON.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (content == null || "".equals(content))
content = "{\"result\":\"0\",\"message\":\"成功\",\"quyuCode\":{\"quyuCode\":320200}}";
System.out.println(content);
return content;
} @Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
try {
if (result != null && !"".equals(result)) {
JSONObject json = new JSONObject(result); if (json.getInt("result") == 0) {
s = json.getString("quyuCode");
addr.setText(s);
// 判断有没有得到取到数据

if (addr.getText().toString() == null
&& "".equals(addr.getText().toString())) {
// pDialog.dismiss();
this.doInBackground(result);
super.onPostExecute(result);
Toast.makeText(SelectCityActivity.this,
"定位失败、请重试...", Toast.LENGTH_SHORT).show();
} else {

pDialog.dismiss();
Intent i = new Intent(); // 传递Data到上一层Activity
i.putExtra("addr", addr.getText().toString());
SelectCityActivity.this.setResult(RESULT_OK, i);
SelectCityActivity.this.finish();
//System.out.println("quyuCode:" + s);
//System.out.println("*******");
}
}
 else {
 Toast.makeText(this.context, "正在定位、请稍后...",
 Toast.LENGTH_LONG).show();
}

} else {
Toast.makeText(this.context, "地址查询错误", Toast.LENGTH_LONG)
.show();
}
} catch (JSONException e) {
Log.e(TAG, "解析quyuCode信息错误:", e);
Toast.makeText(this.context, "地址Code信息错误", Toast.LENGTH_LONG)
.show();
} /*finally {

// pDialog.dismiss();
// Toast.makeText(this.context,"定位成功",Toast.LENGTH_SHORT).show();
}*/
}我个人感觉是不是我判断有问题、测试时候就算取到地址、但不会再次判断然后通过Intent返回数据、必须要取消再次点击、才会判断!