Show Acr User Dialogs loader until end of method xamarin forms (android)

geor_michgeor_mich ✭✭GRMember ✭✭

I use ShowLoading() Acr UserDialogs (v5.2.2) on my xamarin forms project (android and ios) but i wont start loader before start await method and Hide Loader with the end.

My code working on ios but on android nothing happened.

example

async Task MyMethod()
{
UserDialogs.Instance.ShowLoading("Loading",MaskType.Black);
await ViewModel.LoadData();
UserDialogs.Instance.HideLoading();
}

//InsideViewModel
public async Task LoadData();
{
await Task.Yield(); //without this code and ios doesn't work
//download data
}

I add for android UserDialogs.Init(this) on MainActivity.cs

I dont wont Task.Delay(milliseconds) because this method run for some milliseconds. I want something more dynamically because i don't know when downloading finished.

Any help please ? Thanks

Answers

  • JMarcusJMarcus ✭✭✭ USMember ✭✭✭

    void MyMethod() { UserDialogs.Instance.ShowLoading("Loading",MaskType.Black); ViewModel.LoadData().ContinueWith((task) => { UserDialogs.Instance.HideLoading(); }); }

  • geor_michgeor_mich ✭✭ GRMember ✭✭

    Hi @JMarcus , thanks for your time.

    I test your code but with this loader showing very quick and closed on the end of method.

    Loader not started before call LoadData .

  • JMarcusJMarcus ✭✭✭ USMember ✭✭✭

    What does your LoadData method look like?

  • AllanRitchieAllanRitchie ✭✭✭ CAInsider, University ✭✭✭

    You should file stuff like this on github as I monitor it more closely for issues. In this case, the version of the library as well as any logcat statements for when you call for the dialog would be helpful in figuring out your issue.

  • AllanRitchieAllanRitchie ✭✭✭ CAInsider, University ✭✭✭

    PS you should use the following (ensures proper cleanup of dialogs)

    using (UserDialogs.Instance.Loading(...)) {
    await LoadData();
    }

  • geor_michgeor_mich ✭✭ GRMember ✭✭
    edited June 2016

    Hi again @JMarcus My LoadData() looks like .....

    public async Task LoadData ()
    {
    
     await Task.Yield ();
     Runners.Add (new Runner {
     Name = "",
     Location = new Location { Latitude = 0, Longitude = 0},
     Details = "",
     ImageUrl = "",
     IconId = 0,
     PinId = 0,
     Phone = ""
     });
     //add a lot objects in list with big data
     }
    

    and ui freeze when i load the data.

    (i have a binding map and this list is a pins)

    Thanks

  • geor_michgeor_mich ✭✭ GRMember ✭✭
    edited June 2016

    @AllanRitchie-old thanks for your time.

    library is on v.5.2.2 , Xamarin forms v2.0.1.6505 and all Xamarin.Android.Support packages is on v23.0.1.3

    here is the output when i tap load

    Assembly Ref addref MarathonApp[0xb7e4aff0] -> System.Threading.Tasks[0xb7e749e8]: 5
    Assembly Ref addref MarathonApp[0xb7e4aff0] -> Acr.UserDialogs.Interface[0xb7e49ff0]: 3
    Assembly Ref addref MarathonApp[0xb7e4aff0] -> Acr.UserDialogs[0xb7e48f90]: 3
    Assembly Ref addref Acr.UserDialogs[0xb7e48f90] -> AndHUD[0xb7e461c0]: 2
    Assembly Ref addref MarathonApp.Droid[0xb7e31e90] -> Xamarin.Forms.Platform[0xb7e3d4c0]: 3
    Assembly Ref addref MarathonApp.Droid[0xb7e31e90] -> AndHUD[0xb7e461c0]: 3
    Assembly Ref addref MarathonApp.Droid[0xb7e31e90] -> Splat[0xb7e47058]: 4
    [EGL_xap] eglSurfaceAttrib not implemented

    PS: and your code work on iOS but doesn't work for android ....

  • AllanRitchieAllanRitchie ✭✭✭ CAInsider, University ✭✭✭

    @geor_mich please file your issue on github if you believe there is an issue. As an FYI, that is not an exception with a stack trace which is what is needed. If I had to guess because this is android, you haven't called Init properly. Read the docs on github for more info

  • RenjithPRenjithP USMember
    edited September 2016

    For the below tap event, busy indicator is shown only after completing the method DownloadFiles.
    @AllanRitchie Do i have to use async await. ?
    void manualTapped(object sender, EventArgs args)
    {
    busy = UserDialogs.Instance.Loading("Loading...");
    DownloadFiles(scannedResult, "Manuals");
    }

  • AllanRitchieAllanRitchie ✭✭✭ CAInsider, University ✭✭✭

    @RenjithP I have no idea what your code is doing, but if you take a look at the samples on github, it shows examples how to use loading with async

    My guess in this case is to do the following.

    async void manualTapped(object sender, EventArgs args)
    {
    using (UserDialogs.Instance.Loading("Loading..."))
    await DownloadFiles(scannedResult, "Manuals");
    }

  • RenjithPRenjithP USMember

    @AllanRitchie Thanks, i am using the code to download files.

    One more doubt, i am also using the indicator for webview. I have set the Navigated property in xaml. so on loading the site the indicator will dissappear.

    What i have to do if i need to go back while the indicator is still running? Currently back button will work only when indicator dissappears.

Sign In or Register to comment.