5 min read
Android developer learning .NET MAUI: what carries over, what's new, 30-day plan
Practical guide for Android devs transitioning to .NET MAUI, covering transferable skills, new concepts, pitfalls, and a 30‑day learning roadmap.
What carries over
| Android concept | .NET MAUI equivalent | How it translates |
|---|---|---|
| Activity / Fragment lifecycle | Page lifecycle (OnAppearing, OnDisappearing) | The same idea of “entering” and “leaving” a UI surface, but MAUI uses a single page stack rather than separate activity/fragment classes. |
| View binding / findViewById | XAML x:Name + code‑behind fields | XAML creates strongly‑typed fields automatically; you no longer call FindViewById. |
| RecyclerView / Adapter | CollectionView with DataTemplate | MAUI’s CollectionView handles virtualization and item templating out of the box; you supply an ObservableCollection<T> as the ItemsSource. |
| Resources (strings, colors, dimens) | Resources folder (.resx for strings, Colors.xaml for brushes) | The same principle of centralising UI constants, but the file types differ. |
| Dependency Injection (Dagger/Hilt) | Built‑in Microsoft.Extensions.DependencyInjection | Register services in MauiProgram.CreateMauiApp() and inject via constructor parameters. |
| Async/await for background work | Same C# async/await pattern | No change; you already use Task‑based APIs on Android. |
| Navigation drawer / bottom navigation | Shell navigation with FlyoutItem and TabBar | MAUI Shell provides a declarative navigation hierarchy that replaces manual fragment transactions. |
| Unit testing with JUnit | xUnit / NUnit for .NET | Test runners are different, but the test‑first mindset stays the same. |
| Gradle build scripts | dotnet CLI (dotnet build, dotnet run) and MSBuild .csproj | Build concepts (targets, configurations) are analogous; you just use different tooling. |
| ProGuard / R8 shrinking | .NET IL trimming (PublishTrimmed) | Both aim to reduce binary size; MAUI’s trimming works at the IL level. |
The mental models you already have—separating UI from logic, respecting lifecycles, keeping resources external—remain valid. The biggest shift is moving from XML layout files + Java/Kotlin code to XAML + C#.
What's new
UI definition
Android (Kotlin)
// MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.myButton)
button.setOnClickListener {
Toast.makeText(this, "Clicked!", Toast.LENGTH_SHORT).show()
}
}
}
.NET MAUI (C# + XAML)
<!-- MainPage.xaml -->
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
x:Class="MyApp.MainPage">
<StackLayout Padding="20">
<Button x:Name="MyButton"
Text="Click me"
Clicked="OnButtonClicked"/>
</StackLayout>
</ContentPage>
// MainPage.xaml.cs
namespace MyApp;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnButtonClicked(object sender, EventArgs e)
{
DisplayAlert("Info", "Clicked!", "OK");
}
}
What changed and why
- Layout is expressed in XAML, a declarative XML dialect that binds directly to C# fields (
x:Name). - Event wiring uses the
Clickedattribute instead offindViewById+setOnClickListener. DisplayAlertreplacesToast; MAUI provides cross‑platform dialogs out of the box.
Project structure
Android – app/src/main/java/..., AndroidManifest.xml, Gradle files.
MAUI – Single .csproj that targets Android, iOS, Windows, macOS. The same source tree builds for all platforms, and platform‑specific code lives in Platforms/Android/, Platforms/iOS/, etc.
Navigation
Android (Kotlin)
val intent = Intent(this, DetailActivity::class.java)
intent.putExtra("id", itemId)
startActivity(intent)
MAUI (C#)
await Shell.Current.GoToAsync($"detail?id={itemId}");
MAUI Shell centralises routes in AppShell.xaml, removing the need for explicit Intent objects.
Styling
Android – styles.xml, color.xml.
MAUI – Resources/Styles/Colors.xaml, Resources/Styles/Styles.xaml.
MAUI uses ResourceDictionary and supports dynamic theming with AppThemeBinding.
Common pitfalls
- Assuming one‑to‑one API mapping – Not every Android class has a direct MAUI counterpart. For example, there is no
FragmentManager; you use Shell navigation or theNavigationPagestack instead. - XAML binding errors – Forgetting to set
x:Nameor mismatching case in binding paths results in silent failures. Turn onXamlCompilationOptions.Compileto catch them early. - Platform‑specific code placement – Placing Android‑only code in the shared project will cause compile errors. Use
#if ANDROIDor put the file underPlatforms/Android/. - Resource naming – MAUI treats resource keys as case‑sensitive C# identifiers; a resource named
my_colorbecomesMyColorwhen accessed viaResources.Colors.MyColor. - IL trimming surprises – Enabling
PublishTrimmedwithout preserving reflection‑used types can strip needed code. Add<TrimmerRootAssembly Include="MyApp"/>or use[DynamicDependency]attributes when needed. - Threading assumptions – UI updates must happen on the main thread. In Android you used
runOnUiThread; in MAUI you useMainThread.BeginInvokeOnMainThread.
Your 30‑day plan
Week 1 – Foundations
- Install the latest .NET SDK and Visual Studio (or VS Code with the MAUI workload).
- Create a new MAUI app:
dotnet new maui -n SampleApp. Run on an Android emulator. - Explore the project layout:
App.xaml,MainPage.xaml,Platforms/Android/. - Convert a simple Android layout (e.g., a login screen) to XAML, wiring events in code‑behind.
Mini‑project: Build a “Hello World” app that shows a label, a button, and a toast‑like alert when the button is pressed.
Week 2 – Data & MVVM
- Learn the built‑in MVVM support:
BindingContext,ObservableObjectfromCommunityToolkit.Mvvm. - Replace the code‑behind logic with a ViewModel that exposes a
Commandand a boundString. - Implement a
CollectionViewbound to anObservableCollection<Item>and create a data template. - Add a simple SQLite database using
Microsoft.Data.Sqliteand thesqlite-net-pclpackage.
Mini‑project: A notes list where you can add, edit, and delete items; data persists across app launches.
Week 3 – Navigation & Platform Integration
- Define routes in
AppShell.xaml(Flyout, TabBar, and detail pages). - Pass parameters via query strings (
GoToAsync("detail?id=5")) and retrieve them with[QueryProperty]. - Write a small Android‑specific service (e.g., vibration) under
Platforms/Android/and inject it via DI. - Experiment with platform‑specific UI (e.g., using
Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific).
Mini‑project: A master‑detail app where the master list is a CollectionView; tapping an item navigates to a detail page that shows platform‑specific info (Android version, device model).
Week 4 – polishing, testing, and publishing basics
- Add unit tests with
xUnitfor your ViewModels; run them withdotnet test. - Write UI tests using
Microsoft.Maui.TestUtils.DeviceTestsor Appium for Android. - Enable IL trimming and verify the app still runs; add any required
TrimmerRootAssemblyentries. - Build a release APK:
dotnet publish -f:net8.0-android -c:Release /p:AndroidPackageFormat=aab.
Mini‑project: Take the notes app from Week 2, add navigation to a settings page, write a couple of unit tests, and produce a signed AAB ready for the Play Store.
FAQ
Do I need to learn C# from scratch?
If you already know Java or Kotlin, C# feels familiar—both are statically typed, object‑oriented languages with similar syntax for classes, generics, and async/await.
Can I still use existing Android libraries?
You can call Java/Kotlin libraries via Xamarin.Android bindings, but native .NET libraries are preferred for cross‑platform consistency.
How does hot‑reload work in MAUI?
MAUI supports XAML Hot Reload and .NET Hot Reload; changes to XAML or C# are applied to the running app without a full rebuild, similar to Android Studio’s Instant Run.
Is MAUI production‑ready for Android?
Yes. MAUI builds on the stable Xamarin.Android stack and is fully supported for Android 5.0 (API 21) and higher.
Keep going
#android #dotnetmaui #migration #tutorial