Skip to content

fix(android): Drop inflated app start for background-spawned processes on API 35+ - #5841

Merged
alwx merged 9 commits into
mainfrom
alwx/fix/appstart-background-spawn
Jul 30, 2026
Merged

fix(android): Drop inflated app start for background-spawned processes on API 35+#5841
alwx merged 9 commits into
mainfrom
alwx/fix/appstart-background-spawn

Conversation

@alwx

@alwx alwx commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📜 Description

On API 35+, use ApplicationStartInfo.getReason() to detect processes the OS spawned for background work (FCM push, job, service, broadcast, alarm, backup, boot_complete, content_provider) and mark them as not launched in foreground. The first created activity then re-classifies the launch as a warm start re-anchored at activity creation, instead of reporting the whole background idle gap as an inflated cold start.
Reported by a user of RN SDK: getsentry/sentry-react-native#6382

💡 Motivation and Context

When a process is spawned in the background (e.g. by an FCM push) and the user opens the app seconds later, appLaunchedInForeground was only evaluated lazily and the app start span stayed anchored at background process creation. On API 35+ the main-looper idle check that would otherwise mark the launch as headless is skipped once the start type is resolved from ApplicationStartInfo, so the inflated cold start (idle gap up to ~1 min) leaked through into app_start_cold.

Fixes getsentry/sentry-react-native#6382
Fixes #4693

💚 How did you test it?

  • Unit Testing
  • Manual Testing (typical launch vs. background launches like adb shell am broadcast -a io.sentry.samples.android.TEST_BROADCAST -p io.sentry.samples.android.debug)

📝 Checklist

  • I added GH Issue ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • No breaking change or entry added to the changelog.

🔮 Next steps

Follow-up: API < 35 has no reliable process start reason, so a narrow race in the main-looper idle check remains there; not addressed here.

…s on API 35+

When the OS spawns the process for background work (FCM push, job, service,
broadcast, etc.) and the user opens the app later, the app start stayed anchored
at background process creation, inflating the reported cold start by the whole
idle gap.

On API 35+ we now use ApplicationStartInfo.getReason() to detect background
process starts and mark them as not launched in foreground, so the first created
activity re-classifies them as a warm start anchored at activity creation.
@linear-code

linear-code Bot commented Jul 27, 2026

Copy link
Copy Markdown

RN-695

JAVA-164

@sentry

sentry Bot commented Jul 27, 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 28, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 289.42 ms 360.83 ms 71.41 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: alwx/fix/appstart-background-spawn

Startup times

Revision Plain With Sentry Diff
09b6604 315.24 ms 354.90 ms 39.66 ms
b09f940 314.02 ms 363.24 ms 49.22 ms
9c32fdf 318.18 ms 352.44 ms 34.26 ms

App size

Revision Plain With Sentry Diff
09b6604 0 B 0 B 0 B
b09f940 0 B 0 B 0 B
9c32fdf 0 B 0 B 0 B

@alwx
alwx marked this pull request as ready for review July 28, 2026 08:01
@alwx
alwx enabled auto-merge (squash) July 30, 2026 11:20
@alwx
alwx merged commit 6de3962 into main Jul 30, 2026
71 checks passed
@alwx
alwx deleted the alwx/fix/appstart-background-spawn branch July 30, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants