如何使用服务更新的Andr​​oid SQLite数据库 [英] How to use Service to update sqlite database in android

查看:101
本文介绍了如何使用服务更新的Andr​​oid SQLite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够通过从我的活动线程更新SQLite数据库和检索数据。但我需要用更新服务,这将在每5分钟详情更新数据库,无论是我的应用程序运行与否的数据库。因此,当我运行应用程序,我会从当前数据库中获取数据。
我坚持在写服务更新database.Can有人指导。

I am able to update sqlite database and retrieving the data through a thread from my Activity. But i need to update the database using Service, which will update the database in every 5 minute, whether my Application running or not. So when i run the application, i will get data from current database. I am stuck while writing Service to update the database.Can someone guide.

推荐答案

这是您的服务类创建一个定时器对象
定时器定时器=新定时器(); 结果
在上创建

Create a timer object on your service class Timer timer=new Timer();
On on create

@Override
public void onCreate()
{
    super.onCreate();
    timer.schedule(new DelayedTask(),300, 300000);// 300000 is 5min

}

类DelayedTask的

Class DelayedTask

private class DelayedTask extends TimerTask
{

    @Override
    public void run() {
        Log.i(tag,"Timer Task executing");

        // code for updating sqlite database


    }

}

这篇关于如何使用服务更新的Andr​​oid SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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