Search code examples
androidnotificationsbackgroundschedule

Checking Room DB table every seconds in Background and display Notification


I am building a scheduling App, I store all scheduled notification inside a Room DB Table, I want to check every second if the current time/date is equal to the DB Table time/date, and it's should display a notification for it.

How can I do this?


Solution

  • Try something like this

    Handler handler = new Handler();
    int delay = 1000; //milliseconds
    
    handler.postDelayed(new Runnable() {
        public void run() { //DB action here 
            //Todo, here you would put in your DB logic to check if the stuff matches
             handler.postDelayed(this, delay);
        }
    }, delay);