Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

'Random' Crashing of Xamarin form Android App

$
0
0

I am getting a crash of "Unfortunately, App has stopped' at seemingly random times.
This seems to happen when navigating away from a form. So I might have Page A, Page B and Page C. A normal user action would be as follows
Page A, Page B, Page A,Page C,Page A, Page B, Page A,Page C, etc etc
I originally used the navigation method of
Menu x = new Menu();
await this.Navigation.PushAsync(x);

Then tried to use
Navigation.InsertPageBefore(new Menu(), this);
await Navigation.PopAsync().ConfigureAwait(false);

to navigate from C and B to A. This has not made any difference positive or negative, and the crashes continue. Usually after about 10-20 navigations.

I call web services on Pages B and C, however I have extensive error handling on these and only allow navigation after all WS calls have come back.

Thsi wouldbe a WS typical WS call

    public async Task<List<StandardDataItem>> GetPacketDisposeReasons()
    {
        try
        {
            WSCount++;
            // Wrap the HttpClient call in an AssertHttpResponse() - this renews the access token if it has expired and retries the function
            var res = await Helper.AssertHttpResponse(() =>
            {
                var client = Helper.getWebApiClient();

                var url = "packet/GetPacketHoldReasons";
                return client.GetAsync(url);
            });

            if (res.StatusCode == System.Net.HttpStatusCode.OK)
            {
                WSCount--;
                return Newtonsoft.Json.JsonConvert.DeserializeObject<List<StandardDataItem>>(res.Content.ReadAsStringAsync().Result);
            }
            else
            {
                WSCount--;
                return null;
            }
        }
        catch (Exception)
        {
            WSCount--;
            return null;
        }
    }

then before navigation I check like this.

private async void BtnAbandon_OnClicked(object sender, EventArgs e)
{

        if (WSCount == 0)
        {
            bool answer = await DisplayAlert("Abandon?", "Do you really want to abandon this hold operation?", "Yes", "No");
            if (answer)
            {
                //Menu x = new Menu();
                //await this.Navigation.PushAsync(x);
                Navigation.InsertPageBefore(new Menu(), this);
                await Navigation.PopAsync().ConfigureAwait(false);
            }
            else
            {
                await DisplayAlert("WS busy", "Still waiting for WS to complete action", "Ok");
            }
        }

    }

I have also implemented a Garbage Collection call on the Disappearing event as well as cleared all lists that I had used (thought it might be a memory issue.. unlikely I know)

I know a lot of these measures should not be necessary, but I am just trying to find out what is causing these crashes.

I am also using intents on these pages (B and C) as well as a custom entry control from this discussion. https://forums.xamarin.com/discussion/comment/163016/#Comment_163016
@fernandop

Any help or advice much appreciated.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>