的ContentProvider或服务? [英] ContentProvider or Service?

查看:151
本文介绍了的ContentProvider或服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了显示日本传统时代(JTT的简称)的应用程序。有几个组件(通知,部件,程序本身,警报),其全部使用相同的数据 - 当前JTT

I am writing an application that shows "Japanese Traditional Time" (JTT for short). There are several components (notification, widgets, application itself, alarms) which all use the same data - current JTT.

我现在的版本使用一个单一的服务,做所有的计算和使用一个处理程序来通知大家关于滴答滴答,模仿 ACTION_TIME_TICK

My current version uses a single service that does all the calculation and uses a Handler to notify everyone about "ticking", mimicking ACTION_TIME_TICK.

然而,随着报警我也需要有一种方法来平时翻译成JTT,反之亦然。该计算是非常CPU重(这是所有基于日出和日落),因此我preFER拥有一切在一个地方完成,然后缓存(计算的东西知道日出和日落时间不重)。

However with alarms I need to also have a way to translate "usual time" to JTT and vice versa. The calculations are quite CPU-heavy (it's all based on sunrises and sunsets) and thus I prefer having it all done in a single place and then cached (calculating stuff knowing sunrise and sunset times is not as heavy).

所以,我有几个方法可以做到这一点现在:

So I have several ways to do that now:


  • 保持这一切在服务

    • 并使用绑定来请求我需要的数据。它实际上已经在一种情况下完成的,似乎有点麻烦,因为我要处理异步响应


    • 而使用的内容,而不是观察员广播

    • 或者从供应商发送广播


    • 在需要的时候使用内容提供商计算服务,这反过来将播出它的数据

    这将是更好?也许别的东西吗?

    Which would be better? Maybe something else?

    推荐答案

    我与公正服务的坚持 - 我发现这实际上涵盖我有共同的广播问题的持久广播(不必请求服务的最新数据注册后,但得到的第一个滴答),并让我用少得多的情况下,我需要实际的服务连接之前。

    I'm sticking with "just service" - I have discovered Sticky Broadcasts which actually cover the problem I had with common Broadcasts (having to request latest data from service after registering but before getting the first "tick") and that leaves me with much less cases where I need actual service connection.

    这篇关于的ContentProvider或服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆