简体   繁体   中英

How can I use correctly the activity indicator on Xamarin.forms for Android?

I'm using this plugin for showing that the app is busy, but on Android the animation is always stuck.

For example I use it in this code:

private async Task SelectWorkOrderItemAsync(WorkOrderLista WoLista) {
    if (WoLista == null) return;

    // show the loading
    Acr.UserDialogs.UserDialogs.Instance.ShowLoading("Loading..");

    // get datas from DB
    WorkOrderDettaglio WoDett = await _WorkOrderService.GetDettaglioWorkOrder(WoLista.Guid_servizio);

    // this code opens another page with the datas extracted above
    await NavigationService.NavigateToAsync<DettaglioWoViewModel>(WoDett, Costanti.TipoPush.Normale, WoDett.NumWoAnno);

    // hide the loading
    Acr.UserDialogs.UserDialogs.Instance.HideLoading();
}

This is the result:

as you can see, the loading indicator after some seconds become freezed.

This behaviors is the same if I use the default ActivityIndicator.

On IOS all works fine.

How can I correctly use it?

I don't have an Android device/simulator to test at the moment and can't reproduce on UWP, but your service call is being executed asynchronously on the main thread, your ActivityIndicator should not be blocked if you execute your service call in a worker thread.

// get datas from DB
WorkOrderDettaglio WoDett = null;
await Task.Run(async () => WoDett = await _WorkOrderService.GetDettaglioWorkOrder(WoLista.Guid_servizio));

The activity indicator must be binded (isVisibleProperty and isRunningProperty) to a bool property on your ViewModel and your ViewModel must implement

INotifyPropertyChanged

Here is a greate explanation on how to achieve that.

If an overlay is needed in this answer you can find out how to achieve that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM