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