如何在后台 android 的特定时间每天一次在 sqlite 中插入数据?

How to insert data in sqlite once in a day at specific time in android in backgroud?

我的任务是每天 10:00 在后台根据某些条件在 sqlite 中插入或更新一些特定数据。我卡住了。请帮忙。

制作YourReceiver.java文件,

class YourReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().matches(Intent.ACTION_TIME_TICK)) {
            if (check_your_time_with_system_time) {
                // update your DB here
            }
        }
    }
}

在 manifest.xml 中注册您的 Receiver

<receiver android:name=".YourReceiver">
    <intent-filter>
        <action android:name="android.intent.action.TIME_TICK"/>

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</receiver>

YourReceiveronReceive() 方法将每分钟调用一次。