Skip to content

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

Open
markushi wants to merge 1 commit into
mainfrom
markushi/fix-foreground-detection
Open

fix(app-start): Fix detection of foreground app start#5880
markushi wants to merge 1 commit 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
@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Fix detection of foreground app start ([#5880](https://github.com/getsentry/sentry-java/pull/5880))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against df4b9aa

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Fix detection of foreground app start ([#5880](https://github.com/getsentry/sentry-java/pull/5880))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against df4b9aa

@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

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 405.09 ms 496.16 ms 91.07 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

@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 👍

}
}
}
// Fallback, if not matching ApplicationStartInfo is available

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.

Suggested change
// Fallback, if not matching ApplicationStartInfo is available
// Fallback, if no matching ApplicationStartInfo is available

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