In this implementation, application will display a toast message, when Run() method is invoked. And here is the MainActivity class implementation.
And here is the Layout.xml
Now if you run the application and click on the Show Toast button, it will display a toast like this. (I don’t know why the button is showing like that ;) )
This works fine. But what if you want to change the name of the function, from Run() to another, or you want to pass some parameter to this function. To resolve this issue you can find an existing bound interface or virtual class method that provides the name and signature that you want. Then override the method/implement the interface, and things look fairly similar to the example above.
For using the Export attribute, you need to add reference of Mono.Android.Export namespace.(If you are using Starter Edition of Xamarin studio, you need to start the evaluation / trial, otherwise it won’t work. And if you are in trial mode you can see a trial version waring, while running the emulator.). Now run the application, click on the “Invoke Phone dialer” button, it will display a phone dialer activity.
You can find the source code on github â€“ https://github.com/anuraj/CsToJavaSample
Happy Programming :)