【问题标题】:Send location updates to Fragments from Host Activity从 Host Activity 向 Fragments 发送位置更新
【发布时间】:2018-03-26 08:28:02
【问题描述】:

我有一个 Host Activity,它使用 ViewPager (Tabs) 来显示两个 Fragment。

片段 A:显示用户当前位置以及朋友位置的地图片段(从 firebase 获取)。

Fragment B: With check box which when selected send's user's location to firebase for the friends to retrieve and view in their Fragment A.

我目前正在这两个片段中实现位置管理器,但是感觉不对。向这些 Fragment 发送位置更新的更好方法可能是什么。

【问题讨论】:

    标签: android android-fragments android-gps


    【解决方案1】:

    我个人喜欢在主机Activity/Application 中实现位置监听器,然后使用EventBus 将位置传递给任何活动/片段:

     // call this function in onLocationChanged. 
     EventBus.getDefault.post(new LocationUpdateEvent(updatedLocation));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2017-12-10
      • 2011-12-31
      • 2015-08-18
      相关资源
      最近更新 更多