Add code snippets for support-connected-displays.md#843
Conversation
|
Here is the summary of changes. You are about to add 2 region tags.
This comment is generated by snippet-bot.
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces new code examples to enhance the documentation for supporting connected displays within Android Compose adaptive layouts. The goal is to provide practical, runnable code snippets that demonstrate how to retrieve display information and launch activities on external displays, thereby improving the clarity and utility of the related developer guide by replacing any hardcoded examples. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds code snippets for supporting connected displays. The implementation is mostly correct, but I found a potential issue in the launchActivitySnippet where the behavior on older Android versions could be misleading. I've provided a suggestion to improve the clarity and correctness of the snippet.
| val intent = Intent(this, MySecondaryActivity::class.java) | ||
| val options = ActivityOptions.makeBasic() | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
| options.launchDisplayId = externalDisplayId | ||
| } | ||
| startActivity(intent, options.toBundle()) |
There was a problem hiding this comment.
The current implementation will launch the activity on the default display for Android versions below Oreo (API 26), even when an external display is found. This can be misleading for a code snippet that demonstrates launching an activity on a connected display. To make the example clearer and avoid this behavior, the activity should only be launched if the API level is sufficient. Moving the startActivity call and related initializations inside the version check will ensure the activity is only launched on an external display when supported.
| val intent = Intent(this, MySecondaryActivity::class.java) | |
| val options = ActivityOptions.makeBasic() | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| options.launchDisplayId = externalDisplayId | |
| } | |
| startActivity(intent, options.toBundle()) | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
| val intent = Intent(this, MySecondaryActivity::class.java) | |
| val options = ActivityOptions.makeBasic() | |
| options.launchDisplayId = externalDisplayId | |
| startActivity(intent, options.toBundle()) | |
| } |
Code snippets are for:
No snippets left hardcoded on the page.