超时位置

发布于 2024-11-01 07:30:30 字数 825 浏览 3 评论 0原文

我们需要为我们的应用程序提供可从任何地方使用的定位服务。 我们将singletone与应用程序上下文一起用于系统服务等,并有两个基本方法startstop,分别监听位置提供者和停止监听。

我们有 getLastLocation 方法来检索我们能找到的当前最新且最准确的位置。

我们还有另一种方法让我头疼:-)

Location getLocationWithWait(Class c) 应该获取一个位置(如果可用),如果没有,它将返回 null 并创建一个 45 秒的计时器。如果 45 秒已经过去并且没有如果找到位置,则计时器将向参数中给出的类广播“无位置”广播,否则,如果调用位置回调,它们将取消计时器并向参数中的类发送“找到位置”广播。 所以这是我的问题:

  1. 我开始思考整体 这里的建筑是错误的,任何 实现位置的更好方法 满足我的任何活动的服务 应用 ?
  2. 我使用了计时器而不是处理程序,因为 我使用的单音不是 活动所以我没有 Looper 创建一个带有 Looper 外观的线程 对我来说就像创造一样糟糕 计时器的另一个线程...我 确实想使用该活动 相反,但是然后......如果活动 我需要保留暂停和恢复 跟踪计时器的剩余时间。
  3. 广播也可能是 因为如果活动暂停就会出现问题 它将错过广播,然后 我需要跟踪我的 几个状态后的单调, StickyBroadcast 可以解决这个问题,但是 我无法发送到特定的那个 类但仅限于整个系统。

那么最终将此类作为服务有什么好处吗?(说实话,我想到了可能有一个好处,但不多)我想要一个带有超时的位置服务,就像谷歌在地图中的“我的位置”中所做的那样。

10 倍。

We needed a location service for our app that was available from anyplace.
We used s singletone with Application context for system services and more, and has two basic methods start and stop which listen to location providers and stop listening respectively.

We have getLastLocation method that retrieves the current most updated and accurate location we could find.

We have another method that gives me a headache :-)

Location getLocationWithWait(Class c) which supposed to get a location if available, if not it will return null and will create a Timer for 45 seconds.if the 45 seconds have passed and no location was found then the timer will broadcast to the class given in the parameter a 'no location' broadcast, otherwise if the location callbacks will be called they will cancel the timer and will send 'location found' broadcast to the class in the parameter.
So here are my questions:

  1. i started to think the whole
    architecture here is wrong, any
    better way to implement a location
    service to cater ANY Activity in my
    application ?
  2. i used a Timer an not Handler since
    the singletone i use is NOT an
    activity so i have no Looper an
    creating a thread with looper looks
    to me just as bad as creating
    another Thread for the timer... i
    did wanted to use the Activity
    instead, but then... if the activity
    pauses and resumes i need to keep
    track of the timer's remaining time.
  3. the broadcasts may also be of a
    problem since if the activty pauses
    it will miss the broadcast and then
    i need to keep track in my
    singletone after several states,
    StickyBroadcast may solve it but
    that one i can't send to specific
    class but to the whole system only.

So finally will it be any advantage to make this class a Service ?(to be honest i thought of maybe one advantage but not much) i want a location service with timeout much like google do in their "My Location" in maps.

10x.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2024-11-08 07:30:30

使用 LocationListener 不是更好吗,如 < a href="http://developer.android.com/guide/topics/location/obtaining-user-location.html#Updates" rel="nofollow">请求位置更新?

然后,您可以在 onResume()< 中使用“FastFix” /a>

在不了解您的要求的情况下,很难提出更具体的建议。

希望这有帮助,

菲尔·莱洛

Wouldn't it be better to use a LocationListener, as described in Requesting Location Updates?

You can then use a 'FastFix' in onResume()

Without knowing a bit more about your requirements, it's difficult to make more specific suggestions.

Hope this helps,

Phil Lello

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文