SlideShare a Scribd company logo
1 of 34
Using Java
 interop in your
Xamarin.Android
      apps
    @WMeints
Agenda
 Java interop… wait what!?
 Beyond basic interop
 Building your own interop components
JAVA INTEROP, WAIT WHAT?!
Java interop, what what?!
    Building an Android app in C#
namespace TaskTracker.Client.Android
{
    [Activity(Label = "TaskTracker.Client.Android", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : ListActivity
    {
        private TasksOfflineContext _context;

       protected override void OnCreate(Bundle bundle)
       {
           base.OnCreate(bundle);

           _context = new TasksOfflineContext("sync", new Uri("http://10.0.2.2:15314/taskssyncservice.svc/"));

           _context.CacheController.ControllerBehavior.SerializationFormat = SerializationFormat.ODataJSON;


           _context.CacheController.RefreshCompleted += OnRefreshCompleted;
           _context.CacheController.RefreshAsync();
       }
Java interop, what what?!
    Meanwhile in Java country…
public class Activity1 extends android.app.ListActivity implements mono.android.IGCUserPeer
{
         static final String __md_methods;
         static {
                   __md_methods =
                            "n_onCreate:(Landroid/os/Bundle;)V:GetOnCreate_Landroid_os_Bundle_Handlern" +
                            "";
                   mono.android.Runtime.register ("TaskTracker.Client.Android.Activity1, “ +
                            “TaskTracker.Client.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
                            Activity1.class, __md_methods);
         }

         public Activity1 ()
         {
                  super ();
                  if (getClass () == Activity1.class)
                            mono.android.TypeManager.Activate ("TaskTracker.Client.Android.Activity1, “ +
                                     “TaskTracker.Client.Android, Version=1.0.0.0, Culture=neutral, “ …




                                       Cross Platform Mobile Development - Android
Java interop, what what?!

                                          Mono callable wrappers


                     Android
       .NET APIs                   MCW            Android.*        Java.*
                     Bindings

        Mono (.NET Runtime)          ACW           Dalvik (Java Runtime)


                                 Linux Kernel
     Android callable wrappers
Java interop, wait what?!
 What you are essentially doing is building apps
 that rely heavily upon interop.

 In fact: Everything you build on Android will at
 some point talk to a piece Java code.



                 Cross Platform Mobile Development - Android
Java interop, wait what?!
 So why not take advantage of the situation?

 – You can extend your app with Java code
 – Found a cool Android library? Bind it!




                 Cross Platform Mobile Development - Android
BEYOND BASIC INTEROP
Beyond basic interop
 The two-way traffic between Android and
 Mono is done through two endpoints:

 – Mono  Java      Mono Callable Wrappers
 – Java Mono       Android Callable Wrappers




                 Cross Platform Mobile Development - Android
Beyond basic interop - MCWs

                   Android
      .NET APIs                 MCW          Android.*       Java.*
                   Bindings

       Mono (.NET Runtime)        ACW         Dalvik (Java Runtime)


                              Linux Kernel
Beyond basic interop – MCWs
 Talking to Java from .NET is done through the
 Java Native Interface

 – The next bit is going to get pointy or pointerific
   depending on what you like…




                   Cross Platform Mobile Development - Android
Demo

MCW INTERNALS

         Cross Platform Mobile Development - Android
Beyond basic interop – MCWs
 Steps to create an instance of a Java class
 – Find the handle to the type
 – Marshal constructor arguments
 – Invoke the constructor
 – Safe the instance pointer!




                 Cross Platform Mobile Development - Android
Beyond basic interop – MCWs
 Steps to invoke a Java method:
 – Find the handle to the method
 – Marshal the arguments
 – Invoke the method




                 Cross Platform Mobile Development - Android
Beyond basic interop – MCWs
 Notice the TransferOwnership settings

 – Important, who is the owner of the handle?
 – Care must be taken when transferring handles
 – If two objects own a handle, the app will be
   unstable!


                 Cross Platform Mobile Development - Android
Beyond basic interop – MCWs
 Important to know:

 – When invoking JNI, native handles are used
 – Has effect on garbage collection, so clean it up!
 – Please, Reduce the amount of memory copy
   actions, it will improve the performance.


                   Cross Platform Mobile Development - Android
Beyond basic interop - ACWs

                   Android
      .NET APIs                 MCW          Android.*       Java.*
                   Bindings

       Mono (.NET Runtime)        ACW         Dalvik (Java Runtime)


                              Linux Kernel
Demo

ACW INTERNALS

          Cross Platform Mobile Development - Android
Beyond basic interop - ACWs
 Android callable wrappers are the least of your
 problems.

 – Generated by the Mono compiler
 – Don’t touch or you will break them!




                  Cross Platform Mobile Development - Android
Performance considerations
 A few things you need to know:

 – Value types are copied between Java and Mono
 – For reference types pointers are exchanged
 – 4 bytes in .NET != 4 bytes in Java, sometimes

                         Beware Bitmap users!


                 Cross Platform Mobile Development - Android
BUILDING YOUR OWN INTEROP
Building your own interop
 Explicit use of interop is possible from your
 own app through these methods:

 – Add Java source files to your project
 – Create bindings for an existing library




                   Cross Platform Mobile Development - Android
Adding Java sources
 Add a .java file to your project for

 – You found an activity or service that you don’t
   want to translate to .NET code
 – You have a single component, but not enough to
   create a library (Please keep it to one file).



                  Cross Platform Mobile Development - Android
Demo

ADDING JAVA SOURCES

          Cross Platform Mobile Development - Android
Binding Java libraries
 This is the real stuff, the big one, the goodest.

 – Allows you to use existing libraries
 – Automatically generates wrappers for Java classes
   based on the settings you provide.




                  Cross Platform Mobile Development - Android
Binding Java libraries
 The steps for binding a Java library:

 1. Add the Java library to the binding project
 2. Customize the transformations
 3. Extend the library with your own goodies




                  Cross Platform Mobile Development - Android
Binding Java libraries
 The steps for binding a Java library:

 1. Add the Java library to the binding project
 2. Customize the transformations
 3. Extend the library with your own goodies




                  Cross Platform Mobile Development - Android
Demo

BINDING A JAVA LIBRARY

           Cross Platform Mobile Development - Android
Binding Java libraries
 The steps for binding a Java library:

 1. Add the Java library to the binding project
 2. Customize the transformations
 3. Extend the library with your own goodies




                  Cross Platform Mobile Development - Android
Demo

CUSTOMIZING TRANSFORMATIONS

         Cross Platform Mobile Development - Android
Binding Java libraries
 The steps for binding a Java library:

 1. Add the Java library to the binding project
 2. Customize the transformations
 3. Extend the library with your own goodies




                  Cross Platform Mobile Development - Android
Demo

EXTENDING BINDINGS

          Cross Platform Mobile Development - Android
Final thoughts
 Java interop is all around you in
 Xamarin.Android

 – Don’t worry too much about it in your day-to-day
   Android development.
 – Use it when you need it, to get more power!



                  Cross Platform Mobile Development - Android

More Related Content

What's hot

The new java developers kit bag
The new java developers kit bagThe new java developers kit bag
The new java developers kit bagJamie Coleman
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014Minko3D
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with AnsibleCarlo Bonamico
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to MavenJoao Pereira
 
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tls
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tlsSpec et test agile sur mobile @airfrance #at lille & cocoaheads tls
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tlsekito
 
What's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xWhat's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xGeertjan Wielenga
 
Netbeans
NetbeansNetbeans
Netbeansacosdt
 
Automated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsAutomated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsJohn Ferguson Smart Limited
 
Presentation 1 open source tools in continuous integration environment v1.0
Presentation 1   open source tools in continuous integration environment v1.0Presentation 1   open source tools in continuous integration environment v1.0
Presentation 1 open source tools in continuous integration environment v1.0Jasmine Conseil
 

What's hot (12)

The new java developers kit bag
The new java developers kit bagThe new java developers kit bag
The new java developers kit bag
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
 
Netbeans gui tutorial
Netbeans gui tutorialNetbeans gui tutorial
Netbeans gui tutorial
 
Infrastructure as Data with Ansible
Infrastructure as Data with AnsibleInfrastructure as Data with Ansible
Infrastructure as Data with Ansible
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 
An introduction to Maven
An introduction to MavenAn introduction to Maven
An introduction to Maven
 
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tls
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tlsSpec et test agile sur mobile @airfrance #at lille & cocoaheads tls
Spec et test agile sur mobile @airfrance #at lille & cocoaheads tls
 
What's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.xWhat's New in NetBeans IDE 7.x
What's New in NetBeans IDE 7.x
 
Netbeans
NetbeansNetbeans
Netbeans
 
Automated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yardsAutomated Deployment with Maven - going the whole nine yards
Automated Deployment with Maven - going the whole nine yards
 
Presentation 1 open source tools in continuous integration environment v1.0
Presentation 1   open source tools in continuous integration environment v1.0Presentation 1   open source tools in continuous integration environment v1.0
Presentation 1 open source tools in continuous integration environment v1.0
 
Agile Software Development & Tools
Agile Software Development & ToolsAgile Software Development & Tools
Agile Software Development & Tools
 

Viewers also liked

Xamarin Interop - hands on android -
Xamarin Interop - hands on android - Xamarin Interop - hands on android -
Xamarin Interop - hands on android - Alessandro Binhara
 
Search enabled applications with lucene.net
Search enabled applications with lucene.netSearch enabled applications with lucene.net
Search enabled applications with lucene.netWillem Meints
 
Presentation1
Presentation1Presentation1
Presentation1marj3
 
Certificates attained
Certificates attainedCertificates attained
Certificates attainedKush Dalal
 
Exploring Augmented Reality for Practical Purposes
Exploring Augmented Reality  for Practical PurposesExploring Augmented Reality  for Practical Purposes
Exploring Augmented Reality for Practical PurposesSapient Consulting
 
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...Urban Habitat
 
Creating a Better Protective Suit Against Ebola
Creating a Better Protective Suit Against EbolaCreating a Better Protective Suit Against Ebola
Creating a Better Protective Suit Against EbolaSapient Consulting
 
Konzept 100.tagesschau.mobi
Konzept 100.tagesschau.mobiKonzept 100.tagesschau.mobi
Konzept 100.tagesschau.mobiAlex Boerger
 
Wearing Your Heart On Your Sleeve - Literally!
Wearing Your Heart On Your Sleeve - Literally!Wearing Your Heart On Your Sleeve - Literally!
Wearing Your Heart On Your Sleeve - Literally!Barry Caplin
 
Service: The Antidote to Greed
Service: The Antidote to GreedService: The Antidote to Greed
Service: The Antidote to GreedSteve Thomason
 
Britain 2012 and the implications for government communication
Britain 2012 and the implications for government communicationBritain 2012 and the implications for government communication
Britain 2012 and the implications for government communicationIpsos UK
 
Grafico diario del dax perfomance index para el 13 02-2012
Grafico diario del dax perfomance index para el 13 02-2012Grafico diario del dax perfomance index para el 13 02-2012
Grafico diario del dax perfomance index para el 13 02-2012Experiencia Trading
 
KorEsate - Investment Deck
KorEsate - Investment DeckKorEsate - Investment Deck
KorEsate - Investment DeckMike De'Shazer
 
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1f' yagami
 

Viewers also liked (20)

Xamarin Interop - hands on android -
Xamarin Interop - hands on android - Xamarin Interop - hands on android -
Xamarin Interop - hands on android -
 
Search enabled applications with lucene.net
Search enabled applications with lucene.netSearch enabled applications with lucene.net
Search enabled applications with lucene.net
 
Presentation1
Presentation1Presentation1
Presentation1
 
LOS HIJOS
LOS HIJOSLOS HIJOS
LOS HIJOS
 
Certificates attained
Certificates attainedCertificates attained
Certificates attained
 
Exploring Augmented Reality for Practical Purposes
Exploring Augmented Reality  for Practical PurposesExploring Augmented Reality  for Practical Purposes
Exploring Augmented Reality for Practical Purposes
 
God Is Always Just
God Is Always JustGod Is Always Just
God Is Always Just
 
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...
Breaking the Impasse:Balancing the Interests of Public Health & Housing in Af...
 
Creating a Better Protective Suit Against Ebola
Creating a Better Protective Suit Against EbolaCreating a Better Protective Suit Against Ebola
Creating a Better Protective Suit Against Ebola
 
Konzept 100.tagesschau.mobi
Konzept 100.tagesschau.mobiKonzept 100.tagesschau.mobi
Konzept 100.tagesschau.mobi
 
Wearing Your Heart On Your Sleeve - Literally!
Wearing Your Heart On Your Sleeve - Literally!Wearing Your Heart On Your Sleeve - Literally!
Wearing Your Heart On Your Sleeve - Literally!
 
Infographics Creation Guide
Infographics Creation GuideInfographics Creation Guide
Infographics Creation Guide
 
Service: The Antidote to Greed
Service: The Antidote to GreedService: The Antidote to Greed
Service: The Antidote to Greed
 
Britain 2012 and the implications for government communication
Britain 2012 and the implications for government communicationBritain 2012 and the implications for government communication
Britain 2012 and the implications for government communication
 
Grafico diario del dax perfomance index para el 13 02-2012
Grafico diario del dax perfomance index para el 13 02-2012Grafico diario del dax perfomance index para el 13 02-2012
Grafico diario del dax perfomance index para el 13 02-2012
 
Recorte Web - UPA - MediaIN
Recorte Web - UPA - MediaINRecorte Web - UPA - MediaIN
Recorte Web - UPA - MediaIN
 
KorEsate - Investment Deck
KorEsate - Investment DeckKorEsate - Investment Deck
KorEsate - Investment Deck
 
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1
Unsur unsur hara_bagi_pertumbuhan_tanaman_bab_ii1
 
La escuela y yo
La  escuela y yoLa  escuela y yo
La escuela y yo
 
KorEstate
KorEstate KorEstate
KorEstate
 

Similar to Using java interop in your xamarin.android apps

Top Cordova Challenges and How to Tackle Them
Top Cordova Challenges and How to Tackle ThemTop Cordova Challenges and How to Tackle Them
Top Cordova Challenges and How to Tackle ThemIonic Framework
 
NCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsNCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsJohn M. Wargo
 
Hybrid Mobile Applications
Hybrid Mobile ApplicationsHybrid Mobile Applications
Hybrid Mobile ApplicationsRuwan Ranganath
 
Mono for Android... for Google Devs
Mono for Android... for Google DevsMono for Android... for Google Devs
Mono for Android... for Google DevsCraig Dunn
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneAndreas Jakl
 
Universal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptUniversal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptThomas Joseph
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionaswapnal
 
Building Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformBuilding Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformAndrew Ferrier
 
MODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptxMODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptxVeerannaKotagi1
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid DoesKevin McMahon
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Androidcoolmirza143
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Ryan Cuprak
 
Android complete basic Guide
Android complete basic GuideAndroid complete basic Guide
Android complete basic GuideAKASH SINGH
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for androidAdrian Mikeliunas
 

Similar to Using java interop in your xamarin.android apps (20)

Talk (2)
Talk (2)Talk (2)
Talk (2)
 
Improve Android System Component Performance
Improve Android System Component PerformanceImprove Android System Component Performance
Improve Android System Component Performance
 
Mono for android
Mono for androidMono for android
Mono for android
 
Top Cordova Challenges and How to Tackle Them
Top Cordova Challenges and How to Tackle ThemTop Cordova Challenges and How to Tackle Them
Top Cordova Challenges and How to Tackle Them
 
NCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsNCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile Apps
 
Hybrid Mobile Applications
Hybrid Mobile ApplicationsHybrid Mobile Applications
Hybrid Mobile Applications
 
Mono for Android... for Google Devs
Mono for Android... for Google DevsMono for Android... for Google Devs
Mono for Android... for Google Devs
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Universal Applications with Universal JavaScript
Universal Applications with Universal JavaScriptUniversal Applications with Universal JavaScript
Universal Applications with Universal JavaScript
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Building Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformBuilding Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst Platform
 
MODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptxMODULE_1_The History and Evolution of Java.pptx
MODULE_1_The History and Evolution of Java.pptx
 
.NET? MonoDroid Does
.NET? MonoDroid Does.NET? MonoDroid Does
.NET? MonoDroid Does
 
Android - Anroid Pproject
Android - Anroid PprojectAndroid - Anroid Pproject
Android - Anroid Pproject
 
Multithreading in Android
Multithreading in AndroidMultithreading in Android
Multithreading in Android
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 
Android complete basic Guide
Android complete basic GuideAndroid complete basic Guide
Android complete basic Guide
 
Apache cordova
Apache cordovaApache cordova
Apache cordova
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for android
 

More from Willem Meints

Bestuur je 3D printer met blazor
Bestuur je 3D printer met blazorBestuur je 3D printer met blazor
Bestuur je 3D printer met blazorWillem Meints
 
Help et phone home, building bots with Microsoft Bot Framework 4.
Help et phone home, building bots with Microsoft Bot Framework 4.Help et phone home, building bots with Microsoft Bot Framework 4.
Help et phone home, building bots with Microsoft Bot Framework 4.Willem Meints
 
Big data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on AzureBig data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on AzureWillem Meints
 
Agile software ontwikkeling met continuous delivery
Agile software ontwikkeling met continuous deliveryAgile software ontwikkeling met continuous delivery
Agile software ontwikkeling met continuous deliveryWillem Meints
 
Acceptance test driven development
Acceptance test driven developmentAcceptance test driven development
Acceptance test driven developmentWillem Meints
 
Build better mobile apps and become a better person
Build better mobile apps and become a better personBuild better mobile apps and become a better person
Build better mobile apps and become a better personWillem Meints
 
Prototyping windows store apps
Prototyping windows store appsPrototyping windows store apps
Prototyping windows store appsWillem Meints
 
The metro design language for app developers
The metro design language for app developersThe metro design language for app developers
The metro design language for app developersWillem Meints
 

More from Willem Meints (9)

Bestuur je 3D printer met blazor
Bestuur je 3D printer met blazorBestuur je 3D printer met blazor
Bestuur je 3D printer met blazor
 
Help et phone home, building bots with Microsoft Bot Framework 4.
Help et phone home, building bots with Microsoft Bot Framework 4.Help et phone home, building bots with Microsoft Bot Framework 4.
Help et phone home, building bots with Microsoft Bot Framework 4.
 
Big data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on AzureBig data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on Azure
 
Agile software ontwikkeling met continuous delivery
Agile software ontwikkeling met continuous deliveryAgile software ontwikkeling met continuous delivery
Agile software ontwikkeling met continuous delivery
 
Acceptance test driven development
Acceptance test driven developmentAcceptance test driven development
Acceptance test driven development
 
LESS is more
LESS is moreLESS is more
LESS is more
 
Build better mobile apps and become a better person
Build better mobile apps and become a better personBuild better mobile apps and become a better person
Build better mobile apps and become a better person
 
Prototyping windows store apps
Prototyping windows store appsPrototyping windows store apps
Prototyping windows store apps
 
The metro design language for app developers
The metro design language for app developersThe metro design language for app developers
The metro design language for app developers
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Using java interop in your xamarin.android apps

  • 1. Using Java interop in your Xamarin.Android apps @WMeints
  • 2. Agenda Java interop… wait what!? Beyond basic interop Building your own interop components
  • 4. Java interop, what what?! Building an Android app in C# namespace TaskTracker.Client.Android { [Activity(Label = "TaskTracker.Client.Android", MainLauncher = true, Icon = "@drawable/icon")] public class Activity1 : ListActivity { private TasksOfflineContext _context; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); _context = new TasksOfflineContext("sync", new Uri("http://10.0.2.2:15314/taskssyncservice.svc/")); _context.CacheController.ControllerBehavior.SerializationFormat = SerializationFormat.ODataJSON; _context.CacheController.RefreshCompleted += OnRefreshCompleted; _context.CacheController.RefreshAsync(); }
  • 5. Java interop, what what?! Meanwhile in Java country… public class Activity1 extends android.app.ListActivity implements mono.android.IGCUserPeer { static final String __md_methods; static { __md_methods = "n_onCreate:(Landroid/os/Bundle;)V:GetOnCreate_Landroid_os_Bundle_Handlern" + ""; mono.android.Runtime.register ("TaskTracker.Client.Android.Activity1, “ + “TaskTracker.Client.Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", Activity1.class, __md_methods); } public Activity1 () { super (); if (getClass () == Activity1.class) mono.android.TypeManager.Activate ("TaskTracker.Client.Android.Activity1, “ + “TaskTracker.Client.Android, Version=1.0.0.0, Culture=neutral, “ … Cross Platform Mobile Development - Android
  • 6. Java interop, what what?! Mono callable wrappers Android .NET APIs MCW Android.* Java.* Bindings Mono (.NET Runtime) ACW Dalvik (Java Runtime) Linux Kernel Android callable wrappers
  • 7. Java interop, wait what?! What you are essentially doing is building apps that rely heavily upon interop. In fact: Everything you build on Android will at some point talk to a piece Java code. Cross Platform Mobile Development - Android
  • 8. Java interop, wait what?! So why not take advantage of the situation? – You can extend your app with Java code – Found a cool Android library? Bind it! Cross Platform Mobile Development - Android
  • 10. Beyond basic interop The two-way traffic between Android and Mono is done through two endpoints: – Mono  Java Mono Callable Wrappers – Java Mono Android Callable Wrappers Cross Platform Mobile Development - Android
  • 11. Beyond basic interop - MCWs Android .NET APIs MCW Android.* Java.* Bindings Mono (.NET Runtime) ACW Dalvik (Java Runtime) Linux Kernel
  • 12. Beyond basic interop – MCWs Talking to Java from .NET is done through the Java Native Interface – The next bit is going to get pointy or pointerific depending on what you like… Cross Platform Mobile Development - Android
  • 13. Demo MCW INTERNALS Cross Platform Mobile Development - Android
  • 14. Beyond basic interop – MCWs Steps to create an instance of a Java class – Find the handle to the type – Marshal constructor arguments – Invoke the constructor – Safe the instance pointer! Cross Platform Mobile Development - Android
  • 15. Beyond basic interop – MCWs Steps to invoke a Java method: – Find the handle to the method – Marshal the arguments – Invoke the method Cross Platform Mobile Development - Android
  • 16. Beyond basic interop – MCWs Notice the TransferOwnership settings – Important, who is the owner of the handle? – Care must be taken when transferring handles – If two objects own a handle, the app will be unstable! Cross Platform Mobile Development - Android
  • 17. Beyond basic interop – MCWs Important to know: – When invoking JNI, native handles are used – Has effect on garbage collection, so clean it up! – Please, Reduce the amount of memory copy actions, it will improve the performance. Cross Platform Mobile Development - Android
  • 18. Beyond basic interop - ACWs Android .NET APIs MCW Android.* Java.* Bindings Mono (.NET Runtime) ACW Dalvik (Java Runtime) Linux Kernel
  • 19. Demo ACW INTERNALS Cross Platform Mobile Development - Android
  • 20. Beyond basic interop - ACWs Android callable wrappers are the least of your problems. – Generated by the Mono compiler – Don’t touch or you will break them! Cross Platform Mobile Development - Android
  • 21. Performance considerations A few things you need to know: – Value types are copied between Java and Mono – For reference types pointers are exchanged – 4 bytes in .NET != 4 bytes in Java, sometimes Beware Bitmap users! Cross Platform Mobile Development - Android
  • 22. BUILDING YOUR OWN INTEROP
  • 23. Building your own interop Explicit use of interop is possible from your own app through these methods: – Add Java source files to your project – Create bindings for an existing library Cross Platform Mobile Development - Android
  • 24. Adding Java sources Add a .java file to your project for – You found an activity or service that you don’t want to translate to .NET code – You have a single component, but not enough to create a library (Please keep it to one file). Cross Platform Mobile Development - Android
  • 25. Demo ADDING JAVA SOURCES Cross Platform Mobile Development - Android
  • 26. Binding Java libraries This is the real stuff, the big one, the goodest. – Allows you to use existing libraries – Automatically generates wrappers for Java classes based on the settings you provide. Cross Platform Mobile Development - Android
  • 27. Binding Java libraries The steps for binding a Java library: 1. Add the Java library to the binding project 2. Customize the transformations 3. Extend the library with your own goodies Cross Platform Mobile Development - Android
  • 28. Binding Java libraries The steps for binding a Java library: 1. Add the Java library to the binding project 2. Customize the transformations 3. Extend the library with your own goodies Cross Platform Mobile Development - Android
  • 29. Demo BINDING A JAVA LIBRARY Cross Platform Mobile Development - Android
  • 30. Binding Java libraries The steps for binding a Java library: 1. Add the Java library to the binding project 2. Customize the transformations 3. Extend the library with your own goodies Cross Platform Mobile Development - Android
  • 31. Demo CUSTOMIZING TRANSFORMATIONS Cross Platform Mobile Development - Android
  • 32. Binding Java libraries The steps for binding a Java library: 1. Add the Java library to the binding project 2. Customize the transformations 3. Extend the library with your own goodies Cross Platform Mobile Development - Android
  • 33. Demo EXTENDING BINDINGS Cross Platform Mobile Development - Android
  • 34. Final thoughts Java interop is all around you in Xamarin.Android – Don’t worry too much about it in your day-to-day Android development. – Use it when you need it, to get more power! Cross Platform Mobile Development - Android