I am new to the xamarin app development, I have some questions :
Let me explain clearly.
I have a Page XFView.xaml
, XFView.xaml.cs
and XFViewModel.cs
in PCL (Xamarin.Forms) project from XFView.xaml.cs
or XFViewModel.cs
i want to call MAActivity.cs
page which is present in Xamarin.Andriod
project
I tried a lot but got getting any idea.
Go to Solution Explorer-->Your Project-->Portable-->Right click-->Add-->New Item (Ctrl+Shift+A). Now, select Forms XAML page and give the name (MainPage. xaml). In this step, add another one page, whose name is called SecondPage.
Xamarin is one of the most popular cross-platform app development tools for iOS, Android, tvOS, watchOS, macOS, and Microsoft (UWP apps) using C # and . NET. In 2019–2020, it was ranked among the five most popular cross-platform mobile frameworks used by software developers worldwide.
Whenever you would like to call something from native (MAActivity.cs
in your case), you have to use DependencyService.
For example:
Setup dependency service
// PCL Project
public interface INativePages
{
void StartMA();
}
// MonoDroid Project
[assembly: Dependency(typeof(NativePages))]
public class NativePages : INativePages
{
public void StartMA()
{
var intent = new Intent(Forms.Context, typeof(MAActivity));
Forms.Context.StartActivity(intent);
}
}
Invoke in PCL
// PCL Project
DependencyService.Get<INativePages>().StartMA();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With