diff --git a/firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java b/firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java index 07e9955e6db..7574f989d92 100644 --- a/firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java +++ b/firebase-perf/src/main/java/com/google/firebase/perf/metrics/AppStartTrace.java @@ -355,10 +355,12 @@ public synchronized void onActivityResumed(Activity activity) { final boolean isExperimentTTIDEnabled = configResolver.getIsExperimentTTIDEnabled(); if (isExperimentTTIDEnabled) { View rootView = activity.findViewById(android.R.id.content); - rootView.getViewTreeObserver().addOnDrawListener(onDrawCounterListener); - FirstDrawDoneListener.registerForNextDraw(rootView, this::recordOnDrawFrontOfQueue); - PreDrawListener.registerForNextDraw( - rootView, this::recordPreDraw, this::recordPreDrawFrontOfQueue); + if (rootView != null) { + rootView.getViewTreeObserver().addOnDrawListener(onDrawCounterListener); + FirstDrawDoneListener.registerForNextDraw(rootView, this::recordOnDrawFrontOfQueue); + PreDrawListener.registerForNextDraw( + rootView, this::recordPreDraw, this::recordPreDrawFrontOfQueue); + } } if (onResumeTime != null) { // An activity already called onResume() @@ -444,7 +446,9 @@ public void onActivityPaused(Activity activity) { return; } View rootView = activity.findViewById(android.R.id.content); - rootView.getViewTreeObserver().removeOnDrawListener(onDrawCounterListener); + if (rootView != null) { + rootView.getViewTreeObserver().removeOnDrawListener(onDrawCounterListener); + } } @Override