Reputation: 577
am relatively new to Xamarin. I have a solution with Xamarin.Forms project and a Xamarin.Android(Native) project. Is it possible to launch the Activity in the Native module from a 'Page' in Xamarin.forms, say when we click on a button. Also is the same applicable in Xamarin.iOS ?
Upvotes: 0
Views: 767
Reputation: 4358
Is it possible to launch the Activity in the Native module from a 'Page' in Xamarin.forms, say when we click on a button
The answer is yes.
You can use DependencyService to achieve it.
In Android:
1) Define a interface in PCL:
public interface IOpenPage
{
void OpenPage();
}
2) Implement the interface in Android:
[assembly: Dependency(typeof(OpenPageImpl))]
namespace App2.Droid
{
class OpenPageImpl : IOpenPage
{
public void OpenPage()
{
Forms.Context.StartActivity(new Intent(Forms.Context, typeof(TextActivity)));
}
}
}
3) In your button's click event:
private void ToPage(object sender, EventArgs e)
{
DependencyService.Get<IOpenPage>().OpenPage();
}
Xamarin.forms project:
Upvotes: 4