[英]Which type of Android Services should I use?
I try to get services into my weather application. 我尝试将服务纳入我的天气应用程序。 Let's assume that user has set up locations (cities list), and that he tap an Update button. 假设用户已经设置了位置(城市列表),并且他点击了“更新”按钮。 In my case, this tap is caught by MainActivity
. 就我而言,此水龙头被MainActivity
捕获。 After that, the application should read from sqlite user locations to update weather data, loop through this list of locations, for each of them send request to weather provider, parse json and put weather data into database. 之后,应用程序应从sqlite用户位置读取信息以更新天气数据,循环浏览此位置列表,因为每个用户都向天气提供者发送请求,解析json并将天气数据放入数据库中。 On success, the current view should be updated to show data that was just received. 成功后,应更新当前视图以显示刚刚接收到的数据。 How should I separate all this logic between MainActivity
and services, and which type of services should I use? 如何在MainActivity
和服务之间分隔所有这些逻辑,以及应该使用哪种类型的服务? I think, it can be intent service to get the weather from provider and insert it into database, and bound service to update user layout (view). 我认为,可以从提供者那里获取天气并将其插入数据库中,然后通过绑定服务来更新用户布局(视图),这可能是一种意图服务。 Also, when we have a weather update schedule, should be created a service, that runs permanently in the background, and launches weather update process automatically. 另外,当我们有天气更新时间表时,应创建一个服务,该服务在后台永久运行,并自动启动天气更新过程。 Which type of android service schould be used in this case? 在这种情况下,应使用哪种类型的android服务?
Thank you. 谢谢。
There are several methods. 有几种方法。 Just some of them. 只是其中一些。
Application
class. 而且,恕我直言,最有用的方法(尚不存在规范)是将Activity和Service都设置为存储在Application
类内部的接口(侦听器)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.