DEV Community

Switch by Skill
Switch by Skill

Posted on Originally published at switchbyskill.com

Android developer learning .NET MAUI: what carries over, what's new, 30-day plan

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()
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

.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>
Enter fullscreen mode Exit fullscreen mode
// MainPage.xaml.cs
namespace MyApp;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void OnButtonClicked(object sender, EventArgs e)
    {
        DisplayAlert("Info", "Clicked!", "OK");
    }
}
Enter fullscreen mode Exit fullscreen mode

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 Clicked attribute instead of findViewById + setOnClickListener.
  • DisplayAlert replaces Toast; 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)
Enter fullscreen mode Exit fullscreen mode

MAUI (C#)

await Shell.Current.GoToAsync($"detail?id={itemId}");
Enter fullscreen mode Exit fullscreen mode

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

  1. 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 the NavigationPage stack instead.
  2. XAML binding errors – Forgetting to set x:Name or mismatching case in binding paths results in silent failures. Turn on XamlCompilationOptions.Compile to catch them early.
  3. Platform‑specific code placement – Placing Android‑only code in the shared project will cause compile errors. Use #if ANDROID or put the file under Platforms/Android/.
  4. Resource naming – MAUI treats resource keys as case‑sensitive C# identifiers; a resource named my_color becomes MyColor when accessed via Resources.Colors.MyColor.
  5. IL trimming surprises – Enabling PublishTrimmed without preserving reflection‑used types can strip needed code. Add <TrimmerRootAssembly Include="MyApp"/> or use [DynamicDependency] attributes when needed.
  6. Threading assumptions – UI updates must happen on the main thread. In Android you used runOnUiThread; in MAUI you use MainThread.BeginInvokeOnMainThread.

Your 30‑day plan

Week 1 – Foundations

  1. Install the latest .NET SDK and Visual Studio (or VS Code with the MAUI workload).
  2. Create a new MAUI app: dotnet new maui -n SampleApp. Run on an Android emulator.
  3. Explore the project layout: App.xaml, MainPage.xaml, Platforms/Android/.
  4. 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

  1. Learn the built‑in MVVM support: BindingContext, ObservableObject from CommunityToolkit.Mvvm.
  2. Replace the code‑behind logic with a ViewModel that exposes a Command and a bound String.
  3. Implement a CollectionView bound to an ObservableCollection<Item> and create a data template.
  4. Add a simple SQLite database using Microsoft.Data.Sqlite and the sqlite-net-pcl package.

Mini‑project: A notes list where you can add, edit, and delete items; data persists across app launches.

Week 3 – Navigation & Platform Integration

  1. Define routes in AppShell.xaml (Flyout, TabBar, and detail pages).
  2. Pass parameters via query strings (GoToAsync("detail?id=5")) and retrieve them with [QueryProperty].
  3. Write a small Android‑specific service (e.g., vibration) under Platforms/Android/ and inject it via DI.
  4. 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

  1. Add unit tests with xUnit for your ViewModels; run them with dotnet test.
  2. Write UI tests using Microsoft.Maui.TestUtils.DeviceTests or Appium for Android.
  3. Enable IL trimming and verify the app still runs; add any required TrimmerRootAssembly entries.
  4. 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

Originally published at switchbyskill.com.

Top comments (0)