

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456789101112# Android Platform Development Guidelines1314Guidance for Android handler implementations and platform code.1516## Common Build Issues1718### View Namespace Collision1920**Problem:** Both MAUI and Android have a `View` type, causing ambiguous reference errors when implementing Android listeners or using Android View APIs.2122**Namespace collision between:**23- `Microsoft.Maui.Controls.View` (MAUI's View type)24- `Android.Views.View` (Android's native View type)2526**Common symptoms:**27```28error CS0234: The type or namespace name 'Views' does not exist in the namespace 'Android'29error CS0104: 'View' is an ambiguous reference between 'Microsoft.Maui.Controls.View' and 'Android.Views.View'30```3132**When this occurs:**33- Implementing Android listeners: `IOnLayoutChangeListener`, `IOnClickListener`, `IOnTouchListener`34- Using Android View APIs directly35- Working with RecyclerView, ViewGroup, or Android layout classes36- Accessing Android view properties or methods3738**Solution: Use type aliases**3940Add type alias at the top of the file:4142```csharp43using AView = Android.Views.View;44```4546Then use the alias throughout the file:4748```csharp49class LayoutChangeListener : Java.Lang.Object, AView.IOnLayoutChangeListener50{51 public void OnLayoutChange(AView v, int left, int top, int right, int bottom,52 int oldLeft, int oldTop, int oldRight, int oldBottom)53 {54 // Use AView to unambiguously refer to Android.Views.View55 }56}57```5859**Common type aliases used in MAUI Android code:**6061| Alias | Full Type | When to Use |62|-------|-----------|-------------|63| `AView` | `Android.Views.View` | View APIs, listeners |64| `AColor` | `Android.Graphics.Color` | vs `Microsoft.Maui.Graphics.Color` |65| `ALayoutParams` | `Android.Views.ViewGroup.LayoutParams` | Layout parameters |66| `AContext` | `Android.Content.Context` | vs `Microsoft.Maui.ApplicationModel.Context` (rare) |6768**Alternative: Use global:: qualifier**6970If type alias would conflict with existing code:7172```csharp73class MyListener : Java.Lang.Object, global::Android.Views.View.IOnLayoutChangeListener74{75 public void OnLayoutChange(global::Android.Views.View v, ...)76 {77 // Explicit namespace qualification78 }79}80```8182## Android Handler Best Practices8384### Lifecycle Management8586When implementing Android listeners/callbacks in handlers:87881. **Register in ConnectHandler:**89```csharp90protected override void ConnectHandler(RecyclerView platformView)91{92 base.ConnectHandler(platformView);93 _listener = new MyListener(this);94 platformView.AddSomeListener(_listener);95}96```97982. **Unregister in DisconnectHandler:**99```csharp100protected override void DisconnectHandler(RecyclerView platformView)101{102 if (_listener != null)103 {104 platformView.RemoveSomeListener(_listener);105 _listener?.Dispose();106 _listener = null;107 }108 base.DisconnectHandler(platformView);109}110```1111123. **Always dispose Java.Lang.Object derivatives** to prevent memory leaks113114### Thread Safety115116- Android View APIs are **UI-thread-only**117- Handler methods are called on UI thread by default118- If accessing from background thread, use `platformView.Post(() => { })`119120## Quick Reference121122| Issue | Solution |123|-------|----------|124| View ambiguous reference | Add `using AView = Android.Views.View;` |125| Color ambiguous reference | Add `using AColor = Android.Graphics.Color;` |126| Listener not working | Check lifecycle (register/unregister) |127| Memory leak | Ensure Dispose() called on Java.Lang.Object |128| Threading error | Use `platformView.Post()` for UI thread |129| Gradle 401 / Maven dependency failure | Run `./eng/ingest-maven-deps.sh` — see `copilot-instructions.md` |130131## Gradle / Maven Dependency Failures132133CI uses CFSClean which blocks Maven Central. All deps go through the `dotnet-public-maven` Azure Artifacts feed. If a new package hasn't been ingested, CI fails with `XAGRDL0000` / 401. Run `./eng/ingest-maven-deps.sh` locally to fix. Do NOT upgrade Gradle past 8.x (`dotnet/android#10738`).134
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/maui.github/copilot-instructions.md · 23k | Copilot instructions | setuptestlint-formatstyle+6 | 76/100 | 14 days ago | |
| dotnet/maui.github/instructions/ci-copilot-pipeline-security.instructions.md · 23k | Copilot instructions | gitsecuritydeploymentdo-not+1 | 76/100 | 14 days ago | |
| dotnet/maui.github/instructions/collectionview-handler-detection.instructions.md · 23k | Copilot instructions | stylegitdo-not | 73/100 | 14 days ago | |
| dotnet/maui.github/instructions/collectionview-ios.instructions.md · 23k | Copilot instructions | styleperformance | 48/100 | 14 days ago | |
| dotnet/maui.github/instructions/collectionview-windows.instructions.md · 23k | Copilot instructions | stylearch | 52/100 | 14 days ago | |
| dotnet/maui.github/instructions/handler-patterns.instructions.md · 23k | Copilot instructions | styledo-not | 55/100 | 14 days ago | |
| dotnet/maui.github/instructions/helix-device-tests.instructions.md · 23k | Copilot instructions | setupbuildtestarch | 74/100 | 14 days ago | |
| dotnet/maui.github/instructions/layout-system.instructions.md · 23k | Copilot instructions | archapiperformancedo-not | 55/100 | 14 days ago | |
| dotnet/maui.github/instructions/public-api.instructions.md · 23k | Copilot instructions | apido-not | 59/100 | 9 days ago | |
| dotnet/maui.github/instructions/sandbox.instructions.md · 23k | Copilot instructions | buildteststyletesting-strategy+4 | 81/100 | 14 days ago | |
| dotnet/maui.github/instructions/templates.instructions.md · 23k | Copilot instructions | buildteststylearch+1 | 92/100 | 14 days ago | |
| dotnet/maui.github/instructions/xaml-unittests.instructions.md · 23k | Copilot instructions | teststyledocs | 70/100 | 14 days ago | |
| dotnet/maui.github/instructions/collectionview-android.instructions.md · 23k | Copilot instructions | stylearchperformanceagent-behaviour | 52/100 | 14 days ago | |
| dotnet/maui.github/instructions/integration-tests.instructions.md · 23k | Copilot instructions | setupteststyledo-not | 92/100 | 14 days ago | |
| dotnet/maui.github/instructions/performance-hotpaths.instructions.md · 23k | Copilot instructions | styleperformancedo-not | 55/100 | 14 days ago | |
| dotnet/maui.github/instructions/threading-async.instructions.md · 23k | Copilot instructions | styleui | 48/100 | 14 days ago | |
| dotnet/maui.github/instructions/safe-area-ios.instructions.md · 23k | Copilot instructions | stylegit | 43/100 | 14 days ago | |
| dotnet/maui.github/instructions/uitests.instructions.md · 23k | Copilot instructions | setupbuildteststyle+5 | 79/100 | 14 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotnet/roslyn.github/instructions/Compiler.instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 99/100 | 7 days ago | |
| ardalis/CleanArchitecture.github/copilot-instructions.md · 18k | Copilot instructions | buildteststylearch+4 | 96/100 | 14 days ago | |
| dotnet/maui.github/instructions/templates.instructions.md · 23k | Copilot instructions | buildteststylearch+1 | 92/100 | 14 days ago | |
| dotnet/maui.github/instructions/integration-tests.instructions.md · 23k | Copilot instructions | setupteststyledo-not | 92/100 | 14 days ago | |
| dotnet/roslyn.github/copilot-instructions.md · 21k | Copilot instructions | buildteststylearch+3 | 89/100 | 8 days ago | |
| we-promise/sure.github/copilot-instructions.md · 9.3k | Copilot instructions | setuptestlint-formatstyle+10 | 88/100 | 13 days ago | |
| microsoft/WSL.github/copilot-instructions.md · 33k | Copilot instructions | setupbuildtestlint-format+7 | 88/100 | 14 days ago | |
| PowerShell/PowerShell.github/instructions/start-native-execution.instructions.md · 55k | Copilot instructions | buildstylearchgit+1 | 86/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/dotnet-maui-github-instructions-android-instructions)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.