我正在尝试使用 anAsyncTask进行 API 调用并将响应映射到我命名的对象MapInfo,该对象是MainActivity. 然后,我使用MapInfo名为 polyline 的this字段,并使用预构建的 URL 编码器在不同的 API 调用中使用。我遇到的问题是,我在 中AsyncTask返回了MapInfo对象PostExecute(),但是 上的代码MainActivity继续执行,我需要MapInfo先返回对象,然后再继续执行代码。
这是在MainActivity:
public static MapInfo mapInfo = new MapInfo();
OnCreate() {
button.setonClick() {
//some stuff
new AsyncTask blah = blahblah.execute("");
//the above returns a singular MapInfo object and assigns it to mapInfo
String polyline = mapInfo.polyline; //<--This is where the issue is.
}
}
字符串折线为空,在 API 调用中进一步使用。AsyncTask在将折线分配给返回的对象之前,我应该如何“等待”完成?
慕的地10843
慕哥6287543
慕桂英546537
相关分类