@@ -167,20 +167,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
167
167
public void onActivityDestroyed (Activity activity ) {}
168
168
169
169
@ Override
170
- public synchronized void onActivityStarted (Activity activity ) {
171
- if (isScreenTraceSupported () && configResolver .isPerformanceMonitoringEnabled ()) {
172
- // Starts recording frame metrics for this activity.
173
- /**
174
- * TODO: Only add activities that are hardware acceleration enabled so that calling {@link
175
- * FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
176
- */
177
- frameMetricsAggregator .add (activity );
178
- // Start the Trace
179
- Trace screenTrace = new Trace (getScreenTraceName (activity ), transportManager , clock , this );
180
- screenTrace .start ();
181
- activityToScreenTraceMap .put (activity , screenTrace );
182
- }
183
- }
170
+ public synchronized void onActivityStarted (Activity activity ) {}
184
171
185
172
@ Override
186
173
public synchronized void onActivityStopped (Activity activity ) {
@@ -202,7 +189,8 @@ public synchronized void onActivityResumed(Activity activity) {
202
189
// cases:
203
190
// 1. At app startup, first activity comes to foreground.
204
191
// 2. app switch from background to foreground.
205
- // 3. app already in foreground, current activity is replaced by another activity.
192
+ // 3. app already in foreground, current activity is replaced by another activity, or the
193
+ // current activity was paused then resumed without onStop, for example by an AlertDialog
206
194
if (activityToResumedMap .isEmpty ()) {
207
195
// The first resumed activity means app comes to foreground.
208
196
resumeTime = clock .getTime ();
@@ -219,9 +207,24 @@ public synchronized void onActivityResumed(Activity activity) {
219
207
updateAppState (ApplicationProcessState .FOREGROUND );
220
208
}
221
209
} else {
222
- // case 3: app already in foreground, current activity is replaced by another activity.
210
+ // case 3: app already in foreground, current activity is replaced by another activity, or the
211
+ // current activity was paused then resumed without onStop, for example by an AlertDialog
223
212
activityToResumedMap .put (activity , true );
224
213
}
214
+
215
+ // Screen trace is after session update so the sessionId is not added twice to the Trace
216
+ if (isScreenTraceSupported (activity ) && configResolver .isPerformanceMonitoringEnabled ()) {
217
+ // Starts recording frame metrics for this activity.
218
+ /**
219
+ * TODO: Only add activities that are hardware acceleration enabled so that calling {@link
220
+ * FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
221
+ */
222
+ frameMetricsAggregator .add (activity );
223
+ // Start the Trace
224
+ Trace screenTrace = new Trace (getScreenTraceName (activity ), transportManager , clock , this );
225
+ screenTrace .start ();
226
+ activityToScreenTraceMap .put (activity , screenTrace );
227
+ }
225
228
}
226
229
227
230
/** Returns if this is the cold start of the app. */
0 commit comments