Skip to content

Commit 23b84cd

Browse files
committed
move screen trace start to onResum
1 parent 525b580 commit 23b84cd

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/application/AppStateMonitor.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
146146
public void onActivityDestroyed(Activity activity) {}
147147

148148
@Override
149-
public synchronized void onActivityStarted(Activity activity) {
150-
if (isScreenTraceSupported(activity) && configResolver.isPerformanceMonitoringEnabled()) {
151-
// Starts recording frame metrics for this activity.
152-
/**
153-
* TODO: Only add activities that are hardware acceleration enabled so that calling {@link
154-
* FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
155-
*/
156-
frameMetricsAggregator.add(activity);
157-
// Start the Trace
158-
Trace screenTrace = new Trace(getScreenTraceName(activity), transportManager, clock, this);
159-
screenTrace.start();
160-
activityToScreenTraceMap.put(activity, screenTrace);
161-
}
162-
}
149+
public synchronized void onActivityStarted(Activity activity) {}
163150

164151
@Override
165152
public synchronized void onActivityStopped(Activity activity) {
@@ -181,7 +168,7 @@ public synchronized void onActivityResumed(Activity activity) {
181168
// cases:
182169
// 1. At app startup, first activity comes to foreground.
183170
// 2. app switch from background to foreground.
184-
// 3. app already in foreground, current activity is replaced by another activity.
171+
// 3. app already in foreground, current activity is replaced by another activity, or the current activity was paused then resumed without onStop (ex: a dialog pauses the activity, then closing it resumes)
185172
if (activityToResumedMap.isEmpty()) {
186173
// The first resumed activity means app comes to foreground.
187174
resumeTime = clock.getTime();
@@ -198,9 +185,22 @@ public synchronized void onActivityResumed(Activity activity) {
198185
updateAppState(ApplicationProcessState.FOREGROUND);
199186
}
200187
} else {
201-
// case 3: app already in foreground, current activity is replaced by another activity.
188+
// case 3: app already in foreground, current activity is replaced by another activity, or the current activity was paused then resumed without onStop (ex: a dialog pauses the activity, then closing it resumes)
202189
activityToResumedMap.put(activity, true);
203190
}
191+
192+
if (isScreenTraceSupported(activity) && configResolver.isPerformanceMonitoringEnabled()) {
193+
// Starts recording frame metrics for this activity.
194+
/**
195+
* TODO: Only add activities that are hardware acceleration enabled so that calling {@link
196+
* FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
197+
*/
198+
frameMetricsAggregator.add(activity);
199+
// Start the Trace
200+
Trace screenTrace = new Trace(getScreenTraceName(activity), transportManager, clock, this);
201+
screenTrace.start();
202+
activityToScreenTraceMap.put(activity, screenTrace);
203+
}
204204
}
205205

206206
/** Returns if this is the cold start of the app. */

0 commit comments

Comments
 (0)