服务访问数据库 [英] Service accessing a database

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

问题描述

好球员,我也前询问如何创建一个方法,在我的应用始终运行code。它类似于怎么说iMobeter或类似的东西检查你的HP,如果是低于最大值,它会增加它每隔5分钟。

有人告诉我使用这个词,听上去良好的服务。问题是,我需要的是始终在后台运行的服务。另外,我无法创建一个可以访问数据库的服务。我不能使用光标出现在它不支持的方法。

我会AP preciate指向我一个很好的例子,或者更好的方式来做到这一点。

解决方案
  

但问题是,我需要的是始终在后台运行的服务。

这是不可能的。用户可以停止服务时,他们想,如果生活太长时间Android将停止服务。

  

另外,我不能创建一个可以访问数据库的服务。我不能使用光标出现在它不支持的方法。

是的,确实如此。使用 SQLiteOpenHelper ,以同样的方式,你会与一个活动,内容提供商等。

Ok guys, I did ask before on how to create a way to run a code always in my app. It's similar to how say iMobeter or something like that check your hp, if it's less than max it'll add to it every 5 mins.

Some people told me to use service which sounded good. Problem is, I need a service that is always running in the background. Plus, I could not create a service that can access the database. I cant use the cursor there as in it does not support the method.

I would appreciate pointing me to a good example or a better way to do it.

解决方案

Problem is, I need a service that is always running in the background.

That is not possible. Users can stop your service whenever they want, and Android will stop your service if it lives too long.

Plus, I could not create a service that can access the database. I cant use the cursor there as in it does not support the method.

Yes, it does. Use SQLiteOpenHelper, the same way you would with an activity, content provider, etc.

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

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