1

I have done some research and came across this post:

Does Firebase handle threading on Java Server SDK with App Engine?

But the thing is the post is from someone who is using the Google App Engine (GAE) to develop apps along with Firebase. I am not using any servers to assist me such as the Google App Engine (GAE) I am simply using Android Studio to develop my app and then Firebase to take care of backend tasks such as, signing users in and out, uploading and retrieving images, populating common views and list views.

So the questions are:

  1. When I am interacting with Firebase, for example, populating a RecyclerView with images from Firebase do I have to take care of that in a background thread or is Firebase already designed handle background tasks itself?

  2. Also if my app uses the camera intent to allow users to take/upload pictures, do I have to handle that in a background thread as well when I use Firebase to store the images to the backend and pull them back immediately for them to be displayed?

Community
  • 1
  • 1
Equivocal
  • 912
  • 2
  • 14
  • 27
  • Hi. Sorry. I'm a bit confused. If you're using the Android SDK, so long as you use the APIs correctly, what else is there to worry about? – AL. Feb 02 '17 at 02:29
  • 1
    Firebase handles all network request in a separate thread . Camera intent need not be called in separate thread and Firebase storage too manages image uploading by itself . – Rishabh Maurya Feb 02 '17 at 03:05

1 Answers1

2

The way the Firebase Realtime Database SDK handles threading on Android is different than the way it works with the admin (server) SDK. On Android, all your listeners are always going to be invoked on the main thread, every time. All of the queries will be handled on a background thread that you can't control. There is currently no way to change this behavior. If you need your listeners to work on other threads, you will have to schedule that according to your needs.

Generally, with dealing Firebase on Android, you don't worry about its thread and just use the above knowledge for everything you do. The way you interact with other components, such as a camera, is not related to how you deal with Firebase. The general rule applies that if you're going to be doing something lengthy or blocking, you shouldn't do it on the main thread, and Firebase will never force you to do so.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441