alanbi
alanbi

Reputation: 211

Run Java Android application within Xamarin.Android app

I'm working on a Xamarin.Forms app in C# for iOS and Android. I also have the source code for another app that's written for Android devices in Java. This other app is a fully developed app on its own and has its own pages and UI designed already. Would it be possible to run this app within my project, at least just for Android?

For example, let's say I have a button in my app that, when clicked, leads to a new page within the app that starts running the Java app. From there, it's as if users are simply using the Java app, only that there's a back button on the top of the page that leads the users back to the main page of the Xamarin.Android app.

I've looked into Binding a Java Library but it seems like that's primarily for Java libraries rather than full-on applications.

Upvotes: 1

Views: 259

Answers (1)

Morrison Chang
Morrison Chang

Reputation: 12121

From what I could tell you can look into creating a AAR file of the existing Java code:

https://developer.android.com/studio/projects/android-library

Then add the new AAR (with the Java code & resources) to your existing Xamarin project:

https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar

Using Intents on both sides:

https://developer.android.com/guide/components/intents-filters

https://developer.xamarin.com/api/type/Android.Content.Intent/

I would start with a simple Proof of Concept:

  • write a simple Xamarian app with a button to launch the Java Android Activity via intent
  • write a Android app with a button to launch the Xamarian activity via an intent (the back stack for the integrated app may be tricky).
  • Build an AAR out of the Java Android side.
  • Integrate the AAR into the Xamerian app.

Upvotes: 1

Related Questions