Firebase SDK for Android: A tech deep dive - Google I/O 2016

Firebase · 10K views · 2016 · 32:00

Open on YouTube

Software architecture & designTesting, debugging & developer toolsWeb developmenttalkdated

Why Stack Overflow recommends it

Stack Overflow users link it for the specific segments on detecting whether an app is in the foreground, how Firebase components initialize, and using Tasks to wait on multiple Firebase calls.

Recommended by 6 people across 7 different months, 2016 to 2018.

What it is

A 32-minute Google I/O 2016 session from the Firebase team on how the Firebase and Google Play services SDKs for Android are built. It covers app-foreground detection with ActivityLifecycleCallbacks, how Firebase Crash Reporting initializes through a ContentProvider, and the Tasks API for asynchronous work.

What people said

Recommends Kevin O'Neil · 2016-06 · Stack Overflow · on “Call Firebase database from Google App Engine”

You'll need to use the Firebase Server SDK to make server side calls. You can find info on setting that up and using it here: Add Firebase to your Server [LINK] Firebase Server SDK Installation & Setup [LINK] When using Firebase with Google Cloud Endpoints be aware that you'll need to use Firebase methods in conjunction with the Tasks API [LINK] . Since Firebase methods are not blocking, if you don't use Tasks your Endpoint will return before the call you made to Firebase has a chance to return its result. For a brief intro on using tasks check out the link below. Its a talk given at Google I/O 2016. The speaker is talking about Tasks and Firebase on Android but the concepts are the same whe

Recommends Bob Snyder · 2016-06 · Stack Overflow · on “Deal with Firebase crash reporting and custom Application class with custom UncaughtExceptionHandler”

This Google I/O video [this video] includes a description of Crash Reporting starting at 16:30. You might find it helpful.

Recommends Doug Stevenson · 2016-06 · Stack Overflow · on “How does Firebase crash reporting initialize”

Update: There is now a comprehensive blog post about how Firebase components initialize [LINK] . Firebase Crash Reporting (in addition to other Firebase components) initialize in a ContentProvider that's included into your app automatically. ContentProviders are instantiated first, then your Application subclass, then whatever component was invoked (Activity, Service, BroadcastReciever). When your project depends on an Android Library project (aar file), all of its manifest entries are merged into your app, so you get this ContentProvider for free simply by declaring declaring the dependency on firebase-crash. I gave a talk at Google I/O 2016 about how this all works. Jump to 16:22 [this video] f

Recommends Doug Stevenson · 2016-07 · Stack Overflow · on “Only load layout when firebase calls are complete”

I'm currently using a utility class that I created for kicking off multiple loads of data. It will trigger a final Task when all of the listeners are complete. They key here is clever use of the new Task [LINK] facility for asynchronous programming provided by Play Services. You could probably do all this using some other async framework, but Tasks come for free with Play Services and are used in other parts of Firebase, so you may as well learn to use them. :-) I gave a talk at Google I/O 2016 about tasks. Here is a link to a video [this video] that jumps directly to the relevant part of that session. public class FirebaseMultiQuery { private final HashSet<DatabaseReference> refs = new HashSet<>

Recommends kirtan403 · 2016-08 · Stack Overflow · on “Continue execution after data received from multiple location in Firebase”

I have gone with the Tasks API which Firebase uses already. Its great. As mentioned by @qbix , This answer [LINK] does the same thing. The example in the answer explains good. You can also find video link of this API instructions here [this video] . I have tried and tested it. Solves my problem.

Recommends Doug Stevenson · 2016-08 · Stack Overflow · on “Only load layout when firebase calls are complete”

@kirtan403 I spoke about it in some detail at I/O '16. You can watch that here (jumps directly to the part about Tasks). [this video] Should do a blog too....

Recommends kirtan403 · 2016-09 · Stack Overflow · on “Accessing Firebase Database from AsyncTask's Transaction”

I am using TaskCompletionSource, so that I can simply wait for the data to be returned and then continue execution. From Doug Stevenson: [this video]

Recommends Doug Stevenson · 2016-12 · Stack Overflow · on “How to check is app in foreground from service?”

At Google I/O 2016, I gave a talk where one of the topics was how Firebase [LINK] detects if your app is in the foreground. You can use ActivityLifecycleCallbacks [LINK] for that by incrementing a counter for every activity in your app that gets started, then decrementing it for each activity that gets stopped. If the counter is > 1, then your app is in the foreground. The relevant part of the talk can be seen on YouTube here [this video] .

Recommends Fred Porciúncula · 2017-03 · Stack Overflow · on “How to detect when an Android app goes to the background and come back to the foreground”

Edit: the new architecture components brought something promising: ProcessLifecycleOwner [LINK] , see @vokilam's answer [LINK] The actual solution according to a Google I/O talk [this video] : class YourApplication : Application() { override fun onCreate() { super.onCreate() registerActivityLifecycleCallbacks(AppLifecycleTracker()) } } class AppLifecycleTracker : Application.ActivityLifecycleCallbacks { private var numStarted = 0 override fun onActivityStarted(activity: Activity?) { if (numStarted == 0) { // app went to foreground } numStarted++ } override fun onActivityStopped(activity: Activity?) { numStarted-- if (numStarted == 0) { // app went to background } } } Yes. I know it's hard to beli

Recommends Frank van Puffelen · 2018-01 · Stack Overflow · on “Promise in Android, how to implement?”

On Android you'd use Task s for that. In fact, most of the Firebase Android SDK returns Task s, but unfortunately the Firebase Database API predates that and works with its own ValueEventListener class. Firebase's Doug Stevenson is a master at Task s and has: Given a talk about Tasks in Firebase at I/O 2016 [this video] . Written a series of blog posts about Tasks in Firebase [LINK] . Gave an answer to an extremely similar question [LINK] that maps the Firebase listeners to tasks, so that you can use Tasks.whenAll(...) (the equivalent of Promise.all(...) to wait until all items are loaded.