I am making a To-Do list application, and I’d like it on 24 hours to uncheck the tasks that have been checked.
Basically, alter the Checkbox widget’s check.
How, do I approach that?
I have tried using Workmanager, initialising a 24-hour background task when a task is checked.
But, if I use the callBackDispatcher method for the actions to take on 24 hours using work manager plugin, I cannot really update UI of the widgets, or access Lists / methods, etc, because they are in my widget, and callBackDispatcher must be outside.
More details – I store all my data in Firebase rtdb, also, I’d prefer to not use SharedPreferences.
I’d love if any of you could give me a way to approach this.
2
Answers
You can follow a different approach
without relying on WorkManager
. Instead, you can useFirebase's Realtime Database
and implement a mechanism to periodically update the task status.Note : Initialize Firebase Realtime Database in your application. You can refer to Firebase documentation on how to set it up.
Refer : Firebase Realtime Database
Steps :
Timer.periodic
function. This timer will run a callback every24 hours to update the task status
.startPeriodicTaskStatusUpdate
function when your application starts or when the user logs in.if I were you I would create a control table that lists all the affected Checkbox object, checked flag and last checked date. Reset the checked flag using stored procedure that runs every hour to see whether the 24 hour period has lapsed.
SQLite or plain CSV should suffice