Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we need to use background thread for retrieving data using firebase?

I've an android app where I'm retrieving data into a Fragment. And I believe that Firebase manages its asynchronous calls. But still I've doubt the if we need to write the Firebase code in the background thread or not?.

If we need to write it into the background thread then can you please tell which operations takes more time. eg:

mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");

I think that performing this on the main UI thread may become risk full because setting connection between database may sometime take large time.

like image 861
Ayushi bhardwaj Avatar asked Sep 07 '16 12:09

Ayushi bhardwaj


1 Answers

The Firebase Database client performs all network and disk operations off the main thread.

The Firebase Database client invokes all callbacks to your code on the main thread.

So network and disk access for the database are no reason to spin up your own threads or use background tasks. But if you do disk, network I/O or CPU intensive operations in the callback, you might need to perform those off the main thread yourself.

like image 136
Frank van Puffelen Avatar answered Sep 28 '22 19:09

Frank van Puffelen