@@ -146,20 +146,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
146
146
public void onActivityDestroyed (Activity activity ) {}
147
147
148
148
@ 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 ) {}
163
150
164
151
@ Override
165
152
public synchronized void onActivityStopped (Activity activity ) {
@@ -181,7 +168,8 @@ public synchronized void onActivityResumed(Activity activity) {
181
168
// cases:
182
169
// 1. At app startup, first activity comes to foreground.
183
170
// 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
172
+ // current activity was paused then resumed without onStop, for example by an AlertDialog
185
173
if (activityToResumedMap .isEmpty ()) {
186
174
// The first resumed activity means app comes to foreground.
187
175
resumeTime = clock .getTime ();
@@ -198,9 +186,24 @@ public synchronized void onActivityResumed(Activity activity) {
198
186
updateAppState (ApplicationProcessState .FOREGROUND );
199
187
}
200
188
} else {
201
- // case 3: app already in foreground, current activity is replaced by another activity.
189
+ // case 3: app already in foreground, current activity is replaced by another activity, or the
190
+ // current activity was paused then resumed without onStop, for example by an AlertDialog
202
191
activityToResumedMap .put (activity , true );
203
192
}
193
+
194
+ // Screen trace is after session update so the sessionId is not added twice to the Trace
195
+ if (isScreenTraceSupported (activity ) && configResolver .isPerformanceMonitoringEnabled ()) {
196
+ // Starts recording frame metrics for this activity.
197
+ /**
198
+ * TODO: Only add activities that are hardware acceleration enabled so that calling {@link
199
+ * FrameMetricsAggregator#remove(Activity)} will not throw exceptions.
200
+ */
201
+ frameMetricsAggregator .add (activity );
202
+ // Start the Trace
203
+ Trace screenTrace = new Trace (getScreenTraceName (activity ), transportManager , clock , this );
204
+ screenTrace .start ();
205
+ activityToScreenTraceMap .put (activity , screenTrace );
206
+ }
204
207
}
205
208
206
209
/** Returns if this is the cold start of the app. */
0 commit comments