Search code examples
androidrx-javarx-java2rx-android

How to call Rxjava fucntion daily on specific time in Android?


I want to do the alarm type task using rxjava. I'm already using rxjava interval operator but this asks for time interval I don't want to give time interval instead I want to repeat the function daily on 12:00 am.

This is my code for interval-based Rx Observable:

return Observable.interval(delay, TimeUnit.SECONDS).timeInterval()
                .flatMap((Function<Timed<Long>, ObservableSource<CustomTime.TimeTempBuilder>>) longTimed -> getDataManager().getTimeByDate(date));

Purpose: I have a foreground service running daily I have to show the notification at a specific time.


Solution

  • You better not use rx for this. Instead take a look at JobScheduler or WorkManager. In case of use rxjava, your action won't be fired if main thread will be finished by system or user. But WorkManager API provides to you ability to configure a lot of options, including time, which indicated when system should start your job.