Search code examples
androidfirebasefirebase-performance

Firebase Trace Cancellation


I want to measure the time of a task in my app using firebase performance traces; however, I don't want to include time when the user backgrounds the app. I can't find a way to cancel the task if the task is no longer needed.

For example

  1. I start the task
  2. The user backgrounds the app
  3. The user returns to the app
  4. The task continues and completes

How do I ensure that the time the app was backgrounded doesn't affect my metrics? I would assume throwing out those samples would work but there is no cancel method.


Solution

  • If you don't want a trace to be reported, simply don't call stop() on it. A Trace doesn't actively do anything at all until you do call stop().