【发布时间】:2014-06-08 08:26:21
【问题描述】:
情景:
我有两个片段(每个片段都在一个单独的选项卡中)做彼此相关的工作。例如:
public class A extends Fragment{
// Take user input and calculate a geo-location(this works fine)
// User can also mannually enter a location address and the geocoder
// figures out the Lat/Lng of that location.
// Uses a Asych task.
}
public class B extends Fragment{
// This a Google map. Based on Latitude & Longitude
// place a marker at that location(which is provided by class A.)
// Do other Stuff aswell
}
问题:
我想将位置信息传递给 B 类。但是,一旦我完成了我在 A 类中的位置计算,我就无法使用标记更新地图。 我所看到的是,在我的应用程序启动的那一刻,B 类 onCreateView() 方法就会运行。这是我通常放置我的标记功能信息的地方。然而,A 类的 Asych 任务需要一些时间来计算地理位置,因此我还没有 Location 可以提供给 B 类中的标记方法。一旦 Asych 任务完成而无需再次在 A 类中调用 onCreateView() (对于 B 类),是否仍将标记添加到地图?
换句话说
我能否以某种方式传递位置信息(用于标记方法),从而在我的 Asych 任务完成后在谷歌地图上放置一个标记。
【问题讨论】:
-
你可以使用本地广播接收器
-
有一个第三方库叫做eventbus。你可以使用interface作为activity的回调,然后与Fragment B进行通信
标签: android google-maps android-fragments