f-miyu / Plugin.FirebaseAuth

MIT License
61 stars 26 forks source link

Getting "current activity is null" error from VerifyPhoneNumberAsync () even though CurrentActivity is initialized #16

Closed LittleCornerDev closed 3 years ago

LittleCornerDev commented 4 years ago

It works fine for the Xamarin.iOS project, but for Xamarin.Android, the VerifyPhoneNumberAsync() call

await CrossFirebaseAuth.Current.PhoneAuthProvider.VerifyPhoneNumberAsync(CrossFirebaseAuth.Current.Instance, user.PhoneNumber);

is throwing "current activity is null" from the CrossCurrentActivity.Current.Activity ?? check in https://github.com/f-miyu/Plugin.FirebaseAuth/blob/master/Plugin.FirebaseAuth.Android/PhoneAuthProviderWrapper.cs

Plugin.CurrentActivity is initialized (formerly in MainActivity.cs but now in MainApplication.cs as recommended) with no errors as per instructions in https://github.com/jamesmontemagno/CurrentActivityPlugin:

MainActivity.cs OnCreate():

Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);

MainApplication.cs OnCreate():

Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this);

I get the same null error when I call VerifyPhoneNumberAsync() regardless of where I initialize CurrentActivity.

Adding the var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null"); line in my MainActivity.cs directly throws no error.

Is there anything else I could be overlooking?

Dependency Versions

Plugin.FirebaseAuth 1.1.2 Xamarin.Forms 4.4.0.991265

LittleCornerDev commented 3 years ago

no longer happening in latest versions.