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

async/await method crash web services response in android but same code work successfully in other

$
0
0

async/await method crash web services response in android but same code work successfully in window Phone and iOS apps in xamarin Native Appliation.

Xamarin Native Application (PCL)

I have created a Native application using portable Class libarary.

I request to REST API that gives the following response.

    {
    code: 200,
    status: "ok",
    message: "hello"
    }

my Portable class library code in xamarin.forms is

test.xaml.cs

    public class jsonResponseClass
    {
            public string code { get; set; }
            public string status { get; set; }
            public string message { get; set; }
    }
    public partial class test : ContentPage
    {
            public async void getDatas()
            {
                var cl = new HttpClient();
                var result = await cl.GetStringAsync("http://192.168.1.125/apps/jara/web/api/user/test");
                jsonResponseClass des = JsonConvert.DeserializeObject<jsonResponseClass>(result);
                lbl1.Text = des.code + " " + des.status + " " + des.message;
            }
            public test()
            {
                InitializeComponent();
                getDatas();
            }
    }

Main file in Portable class library (PCL)

App.cs

namespace NativeAppsWithWCF
{
    public class App : Application
    {
        public App()
        {
            MainPage = new test();
        }
        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

my visual studio solution explorer is

Using this above code I can successfully show output in iOS and Window Phone Apps.

But when i Run Android apps then crash the apps and not show output.

When i debug android program then cursor remove after this line.

var result = await
cl.GetStringAsync("http://192.168.1.125/apps/jara/web/api/user/test");

After this line i got an error and stop the execution of program.

See the screen after got error..

How to prevent this error ?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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