I am trying to use Montemagno's CrossCurrentActivity plugin to resolve the current activity in a Xamarin.Forms.Android project. However, CrossCurrentActivity.Current.Activity
is always null. What am I doing wrong?
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
global::Xamarin.Forms.Forms.Init(this, bundle);
CrossCurrentActivity.Current.Init(this, bundle);
// CrossCurrentActivity.Current.Activity is NULL
CrossCurrentActivity.Current.Activity = this;
// CrossCurrentActivity.Current.Activity is still NULL
var formsApp = new App(new AndroidInitializer());
_registryContainer = formsApp.Container;
LoadApplication(formsApp);
}
Do not set CrossCurrentActivity.Current.Activity
yourself:CrossCurrentActivity.Current.Activity = this;
According to github project you could init CrossCurrentActivity
in MainActivity.cs
:CrossCurrentActivity.Current.Init(this, bundle);
Alternatively you could init it in application level.
Had the same problem and this is what I added to my MainActivity.cs inside OnCreate method
CrossCurrentActivity.Current.Init(this, savedInstanceState);
CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);
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