uncle_scrooge uncle_scrooge -4 years ago 243
Android Question

Activityindicator stops spinning in Xamarin.forms

I want to use activityindicator in xamarin.forms,Activityindicator shows successfully in the middle of the screen,but the spinning animation stops(stuck), have gone through some of the articles ,but it didnot helped.I Have not tested in other devices,but it doesnot work in Android.Here Are the codes-

private async Task<string> getUrlString(string id)
string url = doSomeWork(id);\\its a long running process where it \\takes around 10 minutes to run,And I cant do it in background for some reasons
return url;
async void Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
await DisplayAlert("", "something", "OK");
activityindicator.IsRunning = true;
await Task.Delay(250); int id=1;
var url =await getUrlString(id);
await Navigation.PushModalAsync(new playerPage());
activityindicator.IsRunning = false;

Answer Source

You try to achive something that is not built for that. When you block the main thread with a long running task, you are not able to tell the main thread he should spinn your activity indicator... why should he do that? He is busy with the long running task.

You have two options:

1) Do not execute long running tasks on the main thread (that's the recommended way)

2) Do not show an animation (like your activity indicator), just show the user a static message "this may take a while... be patient".

But I highly do not recommend you the option 2. Why? The Android system detects, that your app is not responding, when you block the main thread for a long time and may display a message to the user like "app not responding. Do you want to wait or cancel?". Especially then, when the main thread is blocked and the user taps a couple of times on it...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download