Android app crashes when user cancels login with azure providers like Facebook

dai15002 116 Reputation points
2021-06-04T06:47:04.91+00:00

When a user cancels login by using the code below, then tries to login again, the application crashes. I guess it has something to do with the thread still running in the background for the first canceled login attempt. So my question is, how can I handle the cancelation when inside login page but the login is being manually canceled by user (either by tapping the close button on the login page or press the back button)?

   try
                        {
                            MobileServiceUser user = await MyApp.App.Client.LoginAsync(this, MobileServiceAuthenticationProvider.Facebook, "myApp");

                        }catch(InvalidOperationException e)
                        {
                            //doesnt hit the exception when canceling
                            return false;
                        }
Developer technologies | .NET | Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. dai15002 116 Reputation points
    2021-06-04T14:18:22.17+00:00

    I found out the root cause of this problem. This was because I had updated both Microsoft.Azure.Mobile.Client and Microsoft.Azure.Mobile.Client.SQLiteStore from 4.1.2 to the lastest stable 4.2.0 version.

    In the 4.2.1 version, if user canceled the login, the exception InvalidOperationException would actually hit. But in the 4.2.0 version, the exception is not being hit upon canceling and instead causes the whole app to shut down.

    So I wonder how to catch the cancel event by user, if anyone knows?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.