Unable to use ACR User Dialogs

NiklasTeichNiklasTeich Member ✭✭
edited January 2018 in Visual Studio

Greetings!

I'm new to Xamarin but i had a quite good start, and so far, (almost) everything runs really well.
I wanted to integrate ACR User Dialogs to have a solid dialog service on board (for example for calling dialogs in view models).

So i installed Acr.UserDialogs v6.5.1 via NuGet in both Android and iOS projects (its referenced correctly in both projects)
I registered the Acr package in the android MainActivity, like mentioned in the Github doc:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);
            UserDialogs.Init(this);
            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App());

        }
    }

I cleaned and rebuild everything, but i'm still unable to call the user dialog.
For debugging purpose (called from a command)

void CheckConnection()
{

            try
            {

                UserDialogs.Instance.Alert("Foo", "Bar");

            } catch (Exception ex)
            {

                Console.Write(ex.Message);

            }

}

The exception message:

[Acr.UserDialogs] In android, you must call UserDialogs.Init(Activity) from your first activity OR UserDialogs.Init(App) from your custom application OR provide a factory function to get the current top activity via UserDialogs.Init(() => supply top activi...

I don't have a clue why the dialog service is not working.
I already tried differenct positions for calling the UserDialog init, and already the different init call UserDialogs.Init(() => (Activity)Forms.Context).
But still - the dialog crashes.

I'm testing everything via Xamarin Live Player.
Any help would be much appreciated!

Edit: I found this issue on Github (Issue 449, i can't post links in this forum because i'm to new ...) Sounds like Xamarin Live Player can't handle this package, so what can i do? :neutral:

Greetings!
Niklas

Tagged:

Best Answer

Answers

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited January 2018

    Can you try ShowLoading:
    UserDialogs.Instance.ShowLoading("loading");

  • NiklasTeichNiklasTeich Member ✭✭

    No, same exception ...
    The app does not know the UserDialogs instance, because the registration of it is obviously not working :neutral:

  • AllanRitchieAllanRitchie CAInsider, University ✭✭✭
    edited January 2018

    The issue is with Xamarin Live Player, not the library. It doesn't appear to deal with bait & switch libraries properly. Talk to Xamarin.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @NiklasTeich said:
    No, same exception ...
    The app does not know the UserDialogs instance, because the registration of it is obviously not working :neutral:

    Can you add delay code after showloading; only an experiment; don't know it works :

    UserDialogs.Instance.ShowLoading("loading");
    await Task.Delay(TimeSpan.FromSeconds(2));
    

    Use the quote option for comment when reply, it will give notification to us. Otherwise, we don't know the status of your question.

  • NiklasTeichNiklasTeich Member ✭✭
    edited January 2018

    @Sreeee said:
    Can you add delay code after showloading; only an experiment; don't know it works :

    Sadly no, that makes no difference ..

    @AllanRitchie said:
    The issue is with Xamarin Live Player, not the library. It doesn't appear to deal with bait & switch libraries properly. Talk to Xamarin.

    Thanks for the feedback, Allan.
    I will open this issue on bugzilla.

    Edit: Opened as bug #61175 on bugzilla.

    Greetings,
    Niklas

  • biaparbiapar ITMember ✭✭✭

    @JamesMontemagno said:
    This is because we do not call your App's startup code. Remember we are interpreting your source code inside of the Live Player itself. So you are app is not actually compiled or installed. So none of your "oncreate" would get called.

    On iOS it should work, but I am seeing a few interpreting errors and I opened a bug on our side.

    On Android you could inject in via dependency service. However, there is a casting issue with Forms.Context to an Activity due to some Interpreter stuff.

    Hi,

    So, the Xamarin Live Player not support a full debug and running of an app. Is't right?

  • NiklasTeichNiklasTeich Member ✭✭
    edited February 2018

    @biapar said:
    Hi,

    So, the Xamarin Live Player not support a full debug and running of an app. Is't right?

    I stopped using the Live Player because not everything worked with it and yes, i could not debug everything with it.
    Since i'm testing and debugging on an emulator (or on a device of choice) everything works like a charm and can be debugged.

    Greetings,
    Niklas

  • biaparbiapar ITMember ✭✭✭

    @NiklasTeich said:

    @biapar said:
    Hi,

    So, the Xamarin Live Player not support a full debug and running of an app. Is't right?

    I stopped using the Live Player because not everything worked with it and yes, i could not debug everything with it.
    Since i'm testing and debugging on an emulator (or on a device of choice) everything works like a charm and can be debugged.

    Greetings,
    Niklas

    Xamarin Live Player is very "comfortable". I need to test a Bluethoot code ( I use this libhttps://github.com/aritchie/bluetoothle and not this https://www.nuget.org/packages/Plugin.BLE/ because is not compatible with .NET Standard ) and this is not possible on iOS simulator. So I've to debug direct with iPhone ...

  • RicardoBritoBrensRicardoBritoBrens USMember ✭✭
    edited February 25

    Hello There.

    I was stoped in a similar error, Here is my Implementation.

    Point: I was looking for a solution to show a loading activity while a method is validating credentials.

    Plugin: ACR User Dialogs

    Wrong Code:

     try
                {
                    using (UserDialogs.Instance.Loading("Cargando...", null, null, true))
                    { 
                        var result =  authentication.ValidateCredential(user.Username, user.Password);  // Error line
    
                        if (result.Result)
                        {
                            await _pageService.DisplayAlert("Welcome", $"Welcome Again Mr {Username}", "OK");
    
                            Application.Current.MainPage = new UserProfilePage();
                        }
                        else
                        {
                            await _pageService.DisplayAlert("Something went wrong", "Username or Password are not valid", "OK");
                        }
                    }
                }
                catch (Exception exception)
                {
                    await _pageService.DisplayAlert("Error", exception.ToString(), "OK");
                }
    

    Right Code:

    try
                {
                    using (UserDialogs.Instance.Loading("Loading...", null, null, true))
                    { 
                        var result = await Task.Run( ()=> authentication.ValidateCredential(user.Username, user.Password)); // Error line
    
                        if (result)
                        {
                            await _pageService.DisplayAlert("Welcome", $"Welcome Again Mr {Username}", "OK");
    
                            Application.Current.MainPage = new UserProfilePage();
                        }
                        else
                        {
                            await _pageService.DisplayAlert("Something went wrong", "Username or Password are not valid", "OK");
                        }
                    }
                }
                catch (Exception exception)
                {
                    await _pageService.DisplayAlert("Error", exception.ToString(), "OK");
                }
            }
    

    I hope this can help you.

Sign In or Register to comment.