每次在数据库中插入新数据时我都需要创建一个警报(数据库具有将要创建的每个警报的日期和时间值),而不与用户进行任何交互,应用程序必须自动完成。
答案 0 :(得分:0)
通常对于类似这样的内容,您可能希望使用更像Firebase的内容来更新您的数据。
但要做一个计时器,首先要扩展TimerTask:
public class Progress extends TimerTask {
@Override
public void run(){
//this item runs on a separate thread
runOnUiThread(new Runnable() {
@Override
public void run() {
seconds += 0.1;
//this item runs on the main thread
}
});
}
}
然后运行此任务:
Timer timer;
Progress progress;
timer.schedule(progress, 100, 100);
这将每隔0.1秒运行一次计时器。