0

I am trying to sync data from firebase using AbstractThreadedSyncAdapter. For that I have written some firebase onPerformSync method.

The problem is that as soon as this method is called app crashes.

Error on logs: FirebaseApp with name [DEFAULT] doesn't exist

Can anyone help?

  • why you need to sync data manually ? firebase has real time database sync , – Moh'd Awad May 26 '16 at 11:52
  • Hi MrDroid, I am trying to sync all the contact of a user's phone with firebase to see which of them are registered on app. I thought of writing a sync adaptor for this. Is there any better way? – Yogesh Choudhary May 26 '16 at 12:01
  • 2
    Your data is stored in real database in firebase right ? so no need to do sync your data will be sync automaticlly just make addValueEventListener in your app – Moh'd Awad May 26 '16 at 12:05
  • There definitely are situations where you need to sync data to firebase using a syncadapter. Like your app may want to utilize ability to run complex queries on your data using an sqlite db which is not possible with firebase. And people from firebase does recommend using such approach if you want to run such complex queries. – Sreekanth Jul 21 '16 at 12:46

2 Answers2

0

I ended up doing this in the SyncAdapter constructors

if(FirebaseApp.getApps(context).isEmpty()){
        FirebaseApp.initializeApp(context, FirebaseOptions.fromResource(context));
    }

The reason this happens is because the SyncAdapter is configured to run on separate process (:sync). FirebaseApp gets initialized automatically only in main process. So here we have to manually initialize it.

Note: Don't know if this has any implications

Sreekanth
  • 2,887
  • 2
  • 16
  • 30
-1

There's no need for developers to sync data with Firebase. The platform itself has real-time DB sync. It was said on Firebase home page, you don't need to handle any sync stuff.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Oleksandr Nos
  • 332
  • 5
  • 17