Android - 架构决策
背景
我正在编写一个具有两个不同功能的应用程序。
- 加载 GPX 文件并通过指出正确的行进方向和距离来引导用户遵循文件中定义的路线。然后将航点标记为已到达,并在必要时选择下一个。
- 在标准地图小部件上显示路线。
当前想法
我当前的设计是有三个选项卡:菜单、位置、地图。其中菜单用于加载gpx文件和修改设置;位置给出当前位置和行进方向;地图当然是带有路线叠加层的地图小部件。
因此,这提供了四个活动(主应用程序和三个选项卡)。
我将需要一些例程来获取当前位置并对其应用逻辑以计算出当前的最佳位置。另一个跟踪路线和已到达的航路点的例行程序。我的想法是从主活动中产生两个单独的线程(一个用于位置,一个用于路线跟踪),它们具有可由任何活动调用的方法,例如获取位置。路线跟踪还应该使用某种回调机制或事件机制来通知 UI 何时到达航路点。
这样,用户界面可以根据需要进行更新,而且还可以响应位置数据驱动的事件。
问题
这看起来是一组明智的决定,还是有一些我没有考虑到的事情会让我感到惊讶。为手机编写内容与我通常的方式有很大不同(拥有 UI 会带来很大的变化)。
Background
I am writing an application which has two distinct functions.
- Load a GPX file and direct the user to follow the route defined in the file, by pointing the correct direction of travel and distance. Then marking the waypoint as reached and selecting the next as and when necessary.
- Display the route on the standard maps widget.
Current Thinking
My current design is to have three tabs: menu, location, map. Where menu is used for loading the gpx file and amending settings; location gives the current location and direction to travel; and maps is of course the map widget with the route overlay.
So this gives four activities (the main app, and the three tabs).
I am going to need some routine to take the current location and apply logic to it to work out the current best position. Another routine to keep track of the route and what waypoints have been met. My thinking is to have two separate threads (one for location,one for route tracking) spawned from the main activity which have methods which can be called by any of the activities e.g. get position. The route tracking should also use some callback mechanism or event mechanism to inform the UI when a waypoint has been reached.
This way the user interface can update as and when needed, but also responds to events driven from the location data.
Question
Does this seem a sensible set of decisions or is there something I haven't considered which will take me by surprise. Writing for a mobile phone is significantly different to my usual fare (having a UI makes a big change).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将位置和路线跟踪逻辑实现为绑定服务,而不是作为由活动之一生成的线程可能更有意义。有关如何设置和使用的详细信息,请参阅服务指南主题您的应用程序中的服务。
除此之外,你的方法对我来说似乎很合理。
It might make more sense to have the location and route tracking logic implemented as bound services, rather than as threads spawned by one of your activities. See the Services guide topic for more info on how to set up and use a Service in your application.
Other than that, your approach seems pretty sound to me.