11
votes

How do I get the Android context from the Xamarin.Forms PCL project?

I have tried to search stackoverflow but none fit my search.

I am new to Xamarin.Forms and I am trying to learn accessing custom class for android where I need to have an Android Context

2

2 Answers

21
votes

You can access in android project with:

Xamarin.Forms.Forms.Context
2
votes

There is no knowledge about Android Context inside the PCL. You have Access to it only inside Android projects.

If you want your app to behave differently based on the Context in Android applications then you need to abstract this logic by a platform independent interface and access it via a dependency injection container.

I prefer to use the Mvx container shipped with MVVMCross. There is a great tutorial for Injection of Platform Specific Services.