Search code examples
firebasesynchronizationandroid-roomandroid-jobschedulerandroid-workmanager

How to sync firebase with android room local db?


I have an application that has a remote database(firebase) and local database(room). I get my data from firebase and save it in android room. Also, I use rxjava2 to do that. All posts is get from local database. Everything is okey until here. When I put new child to firebase, it doesnt appear in my application instantly. It is not put in local db. I know that I have to update my remote database every time such as every six hours. I had some researxch to do that. Work Manager and JobScheduler can be used but I dont know how to use that. Is there anyone that give me an advise?


Solution

  • WorkManager, part of Jetpack, is a library by Google, that handle deferrable work that requires a guaranteed execution.

    You can read this blog to see if it covers your requirements. The documentation is an excellent starting point and there's a codelab that you can do to try the library itself available both in Java and Kotlin.

    WorkManager uses JobScheduler when it runs on API Level 23+, for older Android versions (WorkManager supports API Level 14+) it uses AlarmManager and Broadcast receivers.