Skip to content

Anr snippets#986

Closed
huewu wants to merge 4 commits into
mainfrom
anr-snippets
Closed

Anr snippets#986
huewu wants to merge 4 commits into
mainfrom
anr-snippets

Conversation

@huewu

@huewu huewu commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Add anr package under misc to add snippets related ANR issues.

  • Create ViewThreadingViolationSnippet.kt
  • Add snippet for switching to Dispatchers.Main in coroutines
  • Add snippet for View.registerCalledFromWrongThreadListener (API 37)

huewu added 2 commits July 21, 2026 14:36
* Create ViewThreadingViolationSnippet.kt
* Add snippet for switching to Dispatchers.Main in coroutines
* Add snippet for View.registerCalledFromWrongThreadListener (API 37)
* Create ViewThreadingViolationSnippet.kt
* Add snippet for switching to Dispatchers.Main in coroutines
* Add snippet for View.registerCalledFromWrongThreadListener (API 37)

# Conflicts:
#	misc/src/main/java/com/example/snippets/anr/ViewThreadingViolationSnippet.kt
@huewu
huewu requested a review from a team as a code owner July 21, 2026 06:22
@snippet-bot

snippet-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Kotlin file, ViewThreadingViolationSnippet.kt, containing code snippets for handling view threading violations, such as switching context using coroutines and registering a CalledFromWrongThreadListener. The feedback suggests using Kotlin's native @Suppress annotation instead of the Java @SuppressWarnings annotation, and correcting the @RequiresApi annotation to target API level 35 instead of 37.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread misc/src/main/java/com/example/snippets/anr/ViewThreadingViolationSnippet.kt Outdated
huewu and others added 2 commits July 21, 2026 06:24
…tionSnippet.kt

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* limitations under the License.
*/

package com.example.snippets.anr

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi Chansuk! Thanks for adding new snippets!

One comment: We're actually discouraging folks from adding to the misc module (because it's getting quite big as a catch-all for everything), and directing people to add to other more-specific modules instead.

What do you think about moving this to the existing "view" module in the snippets repo? you can add a new "anr" folder under there if you'd like.
https://github.com/android/snippets/tree/main/views/src/main/java

Other than that, the change looks good!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SGTM. Will move to view module and send a new PR : )

@huewu huewu closed this Jul 22, 2026
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.

2 participants