⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@markushi
Copy link
Member

@markushi markushi commented Dec 29, 2025

📜 Description

Improves app start type detection by utilizing the main thread idle callback.

Fixes #4920

The firstPost approach as utilized in the papa library does not seem to work on API level 35+ anymore (See square/papa#63)

The changes add:

  • A new firstIdle field to track when the main thread becomes ready
  • Enhanced logic in onActivityCreated() to detect warm starts when activity creation happens after the first main thread idle
  • Comprehensive unit tests covering the new timing logic and edge cases
  • Extended app start critical tests for determining warm/cold app start behavior (also see Add support for Android API level 36 in CI workflow #5030)

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 302.57 ms 320.71 ms 18.15 ms
Size 1.58 MiB 2.20 MiB 635.54 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
f634d01 359.58 ms 433.88 ms 74.30 ms
7314dbe 437.83 ms 505.64 ms 67.81 ms
fcec2f2 328.91 ms 387.75 ms 58.84 ms
ee747ae 382.73 ms 435.41 ms 52.68 ms
d15471f 343.13 ms 361.47 ms 18.34 ms
ee747ae 358.21 ms 389.41 ms 31.20 ms
bbc35bb 298.53 ms 372.17 ms 73.64 ms
fc5ccaf 322.49 ms 405.25 ms 82.76 ms
bbc35bb 324.88 ms 425.73 ms 100.85 ms
d15471f 379.40 ms 470.76 ms 91.36 ms

App size

Revision Plain With Sentry Diff
f634d01 1.58 MiB 2.10 MiB 533.40 KiB
7314dbe 1.58 MiB 2.10 MiB 533.45 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.50 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
bbc35bb 1.58 MiB 2.12 MiB 553.01 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB

Previous results on branch: fix/app-start-warm-detection

Startup times

Revision Plain With Sentry Diff
12d79b2 324.79 ms 404.20 ms 79.41 ms
a0d0a05 303.68 ms 339.38 ms 35.70 ms

App size

Revision Plain With Sentry Diff
12d79b2 1.58 MiB 2.20 MiB 635.40 KiB
a0d0a05 1.58 MiB 2.13 MiB 559.63 KiB

@markushi
Copy link
Member Author

@sentry review

@markushi
Copy link
Member Author

@sentry review

@markushi markushi marked this pull request as ready for review January 16, 2026 11:02
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

// as the next onActivityCreated will treat it as a new warm app start
if (remainingActivities == 0 && !activity.isChangingConfigurations()) {
appLaunchedInForeground = false;
appLaunchedInForeground.setValue(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect boolean value in onActivityDestroyed sets wrong foreground state

Medium Severity

In onActivityDestroyed(), appLaunchedInForeground.setValue(true) is set when the app moves to background, but the original code set it to false. The comment explicitly states "if the app is moving into background", yet the value is inverted. This causes warm starts to potentially be misclassified as cold starts when a user returns from background very quickly (within the same millisecond as firstIdle), because the !appLaunchedInForeground.getValue() check that previously caught this case now fails, and the firstIdle timing check uses strict > comparison which can miss edge cases.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warm starts potentially reported as cold starts for activities in singleTask launch mode

2 participants