Get Android Context in PCL project

后端 未结 2 1546
故里飘歌
故里飘歌 2021-02-20 06:54

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

2条回答
  •  春和景丽
    2021-02-20 07:32

    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.

提交回复
热议问题