Skip to content

Conversation

@markushi
Copy link
Member

@markushi markushi commented Jan 12, 2026

📜 Description

Converts the MainActivity from Java to Kotlin, categorizing all our buttons a bit nicer too.

Also fixes a missing scroll detection bug for Jetpack Compose.

image

requires #5016 to be merged first.

💡 Motivation and Context

Modernizes the sample app to use Kotlin, which is now the recommended language for Android development. This makes the sample more representative of current best practices and simplifies future enhancements.

💚 How did you test it?

Manual testing of the sample app to ensure functionality remains unchanged.

📝 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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@markushi markushi changed the title refactor(samples): Convert Android sample app MainActivity to Kotlin refactor(samples): Convert Android sample app to Jetpack Compose Jan 12, 2026
@markushi markushi changed the title refactor(samples): Convert Android sample app to Jetpack Compose refactor(samples): Convert main screen to Jetpack Compose Jan 16, 2026
@markushi markushi marked this pull request as ready for review January 16, 2026 11:06
@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • Establish native exception mechanisms by supervacuus in #5052

Internal Changes 🔧

  • (android) Update targetSdk to API 36 (Android 16) by markushi in #5016
  • (ci) Write permission for statuses in changelog preview by supervacuus in #5053
  • (samples) Convert main screen to Jetpack Compose by markushi in #5017

🤖 This preview updates automatically when you update the PR.

FileOutputStream(file).use { outputStream ->
val bytes = ByteArray(1024)
while (inputStream.read(bytes) != -1) {
outputStream.write(bytes)
Copy link

Choose a reason for hiding this comment

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

Bug: The file copy loop incorrectly writes the entire buffer instead of the number of bytes read, potentially corrupting the output file with garbage data from previous reads.
Severity: MEDIUM

Suggested Fix

Capture the number of bytes returned by inputStream.read(bytes) into a length variable. Then, call outputStream.write(bytes, 0, length) to ensure only the valid bytes that were just read are written to the output stream.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.kt#L153

Potential issue: The file copy logic reads from an `inputStream` into a `bytes` buffer
but does not use the return value of `inputStream.read(bytes)`, which indicates the
actual number of bytes read. Instead, it calls `outputStream.write(bytes)`, which writes
the entire buffer. On the final read, if the remaining data is smaller than the buffer
size, the buffer will contain valid data followed by stale data from the previous
iteration. Writing the full buffer appends this garbage data to the output file,
resulting in a corrupted file attachment for every Sentry event.

Did we get this right? 👍 / 👎 to inform future reviews.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 306.20 ms 353.86 ms 47.66 ms
Size 1.58 MiB 2.19 MiB 620.06 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
dba088c 365.46 ms 366.31 ms 0.85 ms
d15471f 315.20 ms 370.22 ms 55.02 ms
fc5ccaf 256.80 ms 322.36 ms 65.56 ms
806307f 357.85 ms 424.64 ms 66.79 ms
ee747ae 415.92 ms 470.15 ms 54.23 ms
694d587 312.37 ms 402.77 ms 90.41 ms
fcec2f2 311.35 ms 384.94 ms 73.59 ms
ee747ae 405.43 ms 485.70 ms 80.28 ms
d15471f 310.66 ms 368.19 ms 57.53 ms
abf451a 332.82 ms 403.67 ms 70.85 ms

App size

Revision Plain With Sentry Diff
dba088c 1.58 MiB 2.13 MiB 558.99 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
806307f 1.58 MiB 2.10 MiB 533.42 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
694d587 1.58 MiB 2.19 MiB 620.06 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.51 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
abf451a 1.58 MiB 2.20 MiB 635.29 KiB

Previous results on branch: markushi/feat/restructure-sample-app

Startup times

Revision Plain With Sentry Diff
d499045 350.63 ms 394.56 ms 43.93 ms
0f80cc7 318.59 ms 363.17 ms 44.58 ms

App size

Revision Plain With Sentry Diff
d499045 1.58 MiB 2.19 MiB 620.05 KiB
0f80cc7 1.58 MiB 2.19 MiB 620.05 KiB

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.

primary = Color(resources.getColor(R.color.colorPrimary, theme)),
secondary = Color(resources.getColor(R.color.colorAccent, theme)),
tertiary = Color(resources.getColor(R.color.colorPrimary, theme)),
)
Copy link

Choose a reason for hiding this comment

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

API 23+ method used with minSdk 21

Low Severity

The resources.getColor(int, Theme) method requires API 23+, but the project's minSdk is 21. This causes a NoSuchMethodError crash on API 21-22 devices when MainActivity launches. The @SuppressLint("NewApi") annotation suppresses the lint warning but doesn't prevent the runtime crash. Consider using ContextCompat.getColor() or Compose's colorResource() for backward compatibility.

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.

3 participants