Cross platform mobile development (speaker Vitaly Ilchenko, Binary Studio)
Mono for android
1. Mono for
Android
Developing Android
applications using C# and
.NET
Willem Meints
@wmeints
2. Agenda
Introduction
Android Framework
App model
Java vs. Mono
Bindings
Runtime
Developing Android applications using C# and .NET
3. Android
Open Source Mobile OS from Google
Hardware made by many
– HTC
– Samsung
Developing Android applications using C# and .NET
4. Android
Many manufacturers means
– Many user interfaces
– Many hardware configurations
– Many active OS versions
Developing Android applications using C# and .NET
5. Android - Tools
Developing Android applications using C# and .NET
6. Introducing Mono for Android
Mono for Android is
– .NET Runtime for Android
– Bindings to Android API’s
– Visual Studio 2010 plugin
• MonoDevelop also possible
Uses all the Android SDK tools under the hood
(emulator, adb, etc.)
Developing Android applications using C# and .NET
8. Android - Framework
Applications
Application Framework
Libraries & Runtime
Linux Kernel
Developing Android applications using C# and .NET
9. Android - Framework
Applications Linux Kernel
Drivers for
Application Framework – Display
– Camera
Libraries & Runtime – WiFi
– Audio
– Keypad
Linux Kernel
– Etc.
Developing Android applications using C# and .NET
10. Android - Framework
Applications Dalvik VM
Libraries for
Application Framework – Media
– SQLite
Libraries & Runtime – SSL
– OpenGL
– WebKit
Linux Kernel
– Etc.
Developing Android applications using C# and .NET
12. Android - Framework
Applications Home
Contacts
Application Framework Phone
Browser
Libraries & Runtime
<your app here>
Etc.
Linux Kernel
Developing Android applications using C# and .NET
13. App model - Components
Applications consist of several components
– Activities
– Content Providers
– Broadcast Receivers
– Services
Developing Android applications using C# and .NET
14. App model - Activity lifecycle
Activity Initialize
Launched layout here
onCreate()
Restore
User navigates to onStart() onRestart()
the activity
state here
onResume()
App process comes into the
Another activity
foreground
killed Activity User returns to
The activity is no longer visiblerunning the activity
Apps with higher state
The activitySave
is finishing or being onPause()
priority need
memory here
destroyed by the system
User navigates to
onStop()
the activity
onDestroy()
Activity shut
down
15. App model - Intents
Intent
View View
Intent Broadcast
Activity Intent
Activity Intent
Receiver
Intent
Intent
Content
Provider
Service
Developing Android applications using C# and .NET
16. App model - Intents
Intents are messages routed through the OS
Intents are powerful. They allow:
– Components of one application to be used by
another
– Allows applications to replace core OS
functionality
Developing Android applications using C# and .NET
17. App model
The app model for Mono for Android is the
same as for regular Android apps.
The behind the scenes however…
Cross Platform Mobile Development - Android
18. Mono for Android architecture
Android Android.
.NET APIs MCW Java.*
Bindings *
Mono (.NET Runtime) ACW Dalvik (Java Runtime)
Linux Kernel
Developing Android applications using C# and .NET
21. Mono for Android - Bindings
99,9% of the Android API is bound to .NET
– There’s always a few minor details that work
different or couldn’t be converted (yet!)
Most of the Java API is bound as well.
– These are redundant, but necessary to make some
of the Android stuff work.
Developing Android applications using C# and .NET
22. Mono for Android - Runtime
Android apps are optimized using the linker
– Users don’t need to install the runtime on their
phone. It is included in the package.
Please note:
– While running in debug, the app is not linked
unless you specify that it must be linked
– Linking in debug has effect on the debugging
capabilities
Developing Android applications using C# and .NET
23. Mono for Android - Runtime
Need a library that isn’t bound yet?
– You can generate them yourself from JAR files.
– Project type provided.
24. Some interesting thoughts
Mono for Android is C# for the Android
platform, which means
– You can reuse a lot of code in Windows Phone and
Monotouch apps
– If you split your code correctly of course.
Developing Android applications using C# and .NET
25. Some interesting thoughts
UI UI UI
Business Logic
Device abstraction layer
Device Device Device
Developing Android applications using C# and .NET