Show custom dialog loader to the end of xamarin forms method (android)

I use ShowLoading () Acr UserDialogs (v5.2.2) in my xamarin forms project (android and ios), but I do not start the bootloader until the wait method and Hide Loader with the end run.

My code is running on ios, but nothing happened on android.

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 doesnt work
//download data
}

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

Any help please? Thanks

+4
source share
5 answers

I am writing code that is really fast and works great with Acr User dialogs.

I am using the depedency service, and here is my complete sample code.

PCL Code

    void CallService ()
    {
        Device.BeginInvokeOnMainThread (() => UserDialogs.Instance.ShowLoading ("Loading ...", MaskType.Black));
        Task.Run (async () => {
            await DependencyService.Get<IJsonMethods> ().Load ("SERVICE_URL");
        }).ContinueWith (result => Device.BeginInvokeOnMainThread (() => {

            UserDialogs.Instance.HideLoading ();

            }
        })
        );
    }

Interface

public interface IJsonMethods
{
    Task Load(string url);
}

public async Task Load (string url)
    {
        try{
            using (var http = new HttpClient (new NativeMessageHandler ())) {
                var x = await http.GetAsync (new Uri (url));
                string res = await x.Content.ReadAsStringAsync ();
                MainViewModel.JsonList = JsonConvert.DeserializeObject<ArticleClass.RootObject> (res);
            }
        }catch (Exception ex) {
            MainViewModel.JsonList = null;
        }
    }
+2

:

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

//InsideViewModel
public async Task LoadData();
{
  await Task.Yield(); //without this code and ios doesnt work
  //download data
}
+2

await Task.Yield();.

, :

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

//InsideViewModel
public async Task LoadData()
{
    await DownloadFileAsync("http://url.to.some/file.mp3", "file.mp3");
}

public async Task DownloadFileAsync(string url, string filename) 
{
    var destination = Path.Combine(
    System.Environment.GetFolderPath(
        System.Environment.SpecialFolder.ApplicationData),
        filename);

    await new WebClient().DownloadFileTaskAsync(new Uri(url), destination);
} 
0

. , , , , , , . , i.e.

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

//InsideViewModel
public async Task LoadData();
{
 Task.Run(()=> //download data;);
}

, MyMethod , MyMethod UIThread Command Click.

0

ios, ~~ Device.BeginInvokeOnMainThread( (FunctionName)); ~~ - .. . Device.BeginInvokeOnMainThread(~~ UserDialogs.Instance.ShowLoading() ~~), ,

0

All Articles