This works very well for me.
In xamarin forms in the layout file put this button
<Button Text="Open Facebook"
Margin="20"
Clicked="Button_Clicked"
VerticalOptions="CenterAndExpand"
HorizontalOptions="FillAndExpand"
BackgroundColor="#1b89c0"
TextColor="White"/>
Next the .cs of this layout, I have the button and implementing the dependency service.
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
DependencyService.Get<IBackgroundDependency>().ExecuteCommand();
}
The next step is make a new interface
public interface IBackgroundDependency
{
void ExecuteCommand();
}
and finish with the class inside the android directory.
[assembly: Dependency(typeof(BackgroundDependency_Android))]
namespace AbrirApp.Droid{
public class BackgroundDependency_Android : Java.Lang.Object, IBackgroundDependency
{
public void ExecuteCommand()
{
Intent intent = new Intent();
intent.SetFlags(ActivityFlags.NewTask);
intent.SetComponent(new ComponentName("com.example.averesta", "com.example.averesta.MainActivity"));
Android.App.Application.Context.StartActivity(intent);
}
}
}
new ComponentName("Package name", "Package name activity")
In my case the main application is in xamarin, and the invoked application is in android studio.