Skip to content

fix(app-start): Fix detection of foreground app start - #5880

Merged
markushi merged 4 commits into
mainfrom
markushi/fix-foreground-detection
Jul 31, 2026
Merged

fix(app-start): Fix detection of foreground app start#5880
markushi merged 4 commits into
mainfrom
markushi/fix-foreground-detection

Conversation

@markushi

Copy link
Copy Markdown
Member

Description

Pre Android 15, AppStartMetrics.appLaunchedInForeground uses a LazyEvaluator<Boolean> that only
evaluated ContextUtils.isForegroundImportance() on the first read. Since the read can happen at a later point in time, e.g. during Activity.onCreate() the process importance might have changed by now, and we incorrectly detect foreground / background starts - causing long app starts.

This PR changes the behavior, and we now immediately evaluate the foreground flag. This will make foreground/background app starts pre Android 15 more correct, at the cost of an extra binder call via ContextUtils.isForegroundImportance().

💡 Motivation and Context

Fixes #4693 (pre Android 15)

💚 How did you test it?

Unit Tests.

📝 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.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

@markushi
markushi requested a review from adinauer as a code owner July 30, 2026 16:52
@markushi markushi added the sanity-check PR needs a lightweight review for obvious issues label Jul 30, 2026
@sentry

sentry Bot commented Jul 30, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.51.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 319.33 ms 370.81 ms 51.48 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 343.31 ms 417.23 ms 73.91 ms
d15471f 342.08 ms 415.44 ms 73.35 ms
8687935 332.52 ms 362.23 ms 29.71 ms
5b1a06b 352.27 ms 413.70 ms 61.43 ms
91bb874 314.47 ms 440.00 ms 125.53 ms
0ee65e9 321.06 ms 361.24 ms 40.18 ms
e63ad34 323.67 ms 390.33 ms 66.67 ms
33a08cc 267.08 ms 340.45 ms 73.37 ms
27d7cf8 397.90 ms 498.65 ms 100.75 ms
ee747ae 405.43 ms 485.70 ms 80.28 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
8687935 1.58 MiB 2.19 MiB 619.17 KiB
5b1a06b 0 B 0 B 0 B
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
0ee65e9 0 B 0 B 0 B
e63ad34 0 B 0 B 0 B
33a08cc 1.58 MiB 2.12 MiB 555.28 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB

Previous results on branch: markushi/fix-foreground-detection

Startup times

Revision Plain With Sentry Diff
558d8e3 405.09 ms 496.16 ms 91.07 ms

App size

Revision Plain With Sentry Diff
558d8e3 0 B 0 B 0 B

@0xadam-brown 0xadam-brown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

Approving pending addition of the CHANGELOG entry 👍

@markushi
markushi merged commit 462dea2 into main Jul 31, 2026
76 of 77 checks passed
@markushi
markushi deleted the markushi/fix-foreground-detection branch July 31, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long ui.load transactions exceeding deadlineTimeout for Android Activities

2 participants