9

I'm extremely curious how there is 0 code written within the application and all that is required is to use the library

compile 'com.google.firebase:firebase-crash:9.0.1'

in order to get firebase crash reporting working. Is the initialization always a one time thing like how the application class' onCreate is always called just once?

What do I do if i want to enable crash reporting only after a certain event?

2 Answers 2

10

Update: There is now a comprehensive blog post about how Firebase components initialize.

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 for the beginning of the content specific to crash reporting.

Unfortunately there is currently no way to programmatically enable or disable crash reporting, but that is coming soon.

8
  • I'll be sure to check it out! So are providers also initialized just once? From your comment I would assume so
    – gaara87
    Jun 10, 2016 at 17:49
  • Yes, all ContentProviders go through onCreate() just once at the beginning of the main process. Jun 10, 2016 at 17:59
  • I just watched the video, explains it perfectly, thank you! The reason why i was asking is to see if theres an alternative to placing app initialization code somewhere other than Application sublcass simply to reduce the cold startup time. I suppose, initializing it in content providers would not help in the reduction right?
    – gaara87
    Jun 10, 2016 at 18:08
  • That's correct. All ContentProvider.onCreate and Application.onCreate all contribute to the time it takes to get the app process fully launched. If you want to kick off a thread to do something async, that's fine. You'll just need to make sure that whatever other code that depends on the results of the async init is sensitive to the fact that it may not be complete yet, and that creates whole new problems for you to solve. :-) Jun 10, 2016 at 19:24
  • Sigh, i was hoping to make things more async as you mentioned, but after profiling, the firebase crash init takes 200 ms on a blocking thread which seems fairly costly - nimbledroid.com/my_apps/…
    – gaara87
    Jun 10, 2016 at 19:27
0

So basically when I'm using Firebase Crash Reporting then I'm forced to do initialization in ContentProvider. My app have 2 processes because of this and if I do init in Application.onCreate then it's called twice - once for each process. But other processes don't care about my init code so I don't want to do it twice. So I can use a ContentProvider or check current process name. Or maybe there is anything else that I'm missing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.