Android - 频繁更新的数据库与业务逻辑
我正在开发一个应用程序,其中至少使用 5 个具有不同初始时间的倒计时器。我从 Sqlite 数据库加载初始时间和其他信息,并使用 Activity 向用户显示这些计时器的状态。我需要每秒用计时器信息填充 ListView 。通常初始时间可能长达 2 或 3 小时,因此我为业务逻辑开发了一个服务,并为每个计时器开发了一个 CountdownTimer。
您认为将 GUI 直接与数据库绑定是一个好主意还是使用一些业务逻辑对象作为中间人更好?
我在这个问题中读到,在Android中大多数文档显示数据库和GUI的绑定。他们回答说,出于性能原因,这种方法更可取,但我认为这不是我的情况。
I am developing an application where I use at least 5 Countdown timer with different initial time. I load the initial time together with other information from a Sqlite db and use an Activity to show the user the state of these timers. I need to populate a ListView with timers informations every seconds. Usually the initial time can be 2 or 3 hour long so I developed a Service for the business logic and a CountdownTimer for each timer.
Do you think is a good idea binding the GUI directly with the db or it's better to use some business logic objects as middle-man?
I read in this question that in Android most of the docs show the binding of database and GUI. They answered that this approach is preferable for performance reasons but I think that's not my case.
我完成了。最后,我决定将 GUI 绑定到我的业务逻辑对象,并仅在计时器启动之前从数据库构建该对象。每个计时器滴答声我只更改内存中的业务逻辑对象。我意识到这样我需要更新数据库的次数更少,只有当计时器被卡住时。我认为这样我的应用程序会更快。
I finished. At last I decided to bind the GUI to my business logic objects and building this objects from the database only before the timer is started. Every timer tick I change only the business logic objects in memory. I realized this way I need to update my db fewer times, only when the timer is stuck. I think this way my application is faster.