在我的应用程序中,我需要定期更新从服务器更新的联系人列表,组列表和文件夹列表。我现在将它们保存到保存偏好设置中。目前我已经实现了一种方法,如果我有我需要的每种类型的列表,我会跳过登录更新并调用一个后台asyncTask,它在登录后更新此数据。问题在于用户可以登录的连接很低,但是他们不能做任何事情,等待阻止其他http请求的后台更新。 如何定期刷新这些数据?就像即使应用程序未处于活动状态也会更新数据的服务一样。在后台更新数据
Q
在后台更新数据
0
A
回答
0
您应该使用Service
。
的manifest.xml
<service
android:name="MyService"
android:icon="@drawable/icon"
android:label="@string/service_name">
</service>
MyService.java
public class MyService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
//TODO do something useful
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
//TODO for communication return IBinder implementation
return null;
}
}
启动服务
// use this to start and trigger a service
Intent i= new Intent(context, MyService.class);
// potentially add data to the intent
i.putExtra("KEY1", "Value to be used by the service");
context.startService(i);
相关问题
- 1. 核心数据在后台更新
- 2. 在后台更新数据库
- 3. 更新数据库和网站后台
- 4. swift3 - 用后台数据更新ui
- 5. 更新数据后更新数据表
- 6. 在后台更新NSManagedObjects
- 7. Android后台更新
- 8. 核心数据在后台线程上处理更新缓慢
- 9. 在后台抓取中使用URLSession更新数据
- 10. 在后台提取数据,但表格视图不更新
- 11. 在后台数据库更新有问题
- 12. 在后台获取核心数据更新的最佳方式
- 13. 在Android上的后台线程中更新SQLite数据库
- 14. 守护进程软件在后台更新mysql数据库
- 15. ListView在更改数据后未更新
- 16. 在网格数据源在后台更新时自动刷新radgrid telerik asp.net
- 17. 更新数据库后GridView不更新
- 18. UI不更新后台bean
- 19. 停止CoreLocation后台更新
- 20. 从后台更新plist
- 21. UIProgressView更新后台线程
- 22. Android后台位置更新?
- 23. Leap Motion JS - 后台更新
- 24. 自jvm后台更新
- 25. 后台位置更新
- 26. 从后台更新UIProgressView
- 27. 如何在后台从Web服务中获取数据,然后更新UI
- 28. IOS:API调用后,可能会更新到核心数据在后台线程?
- 29. 从后台更新前台活动
- 30. 缓存数据,但在后台检查新数据
发布您的代码。 – 2014-09-29 07:28:37