user5680859
user5680859

Reputation:

How to close an activity after timeout

I have login screen in android app which having 45 sec timeout period, it also shows the popup that 'Time out' but after that activity did't close or finish there on click of popup app crash

public HttpClient Client
        {
            get
            {
                if (_client != null) return _client;


                var httpClient = new HttpClient(new NativeMessageHandler {UseCookies = false});
                httpClient.BaseAddress = new Uri(ApplicationSettings.BaseServiceUrl);
                httpClient.Timeout = TimeSpan.FromMilliseconds(45000);
                return _client = httpClient;

            }
        }

        public HttpClient ClientPreAuthenticated
        {
            get
            {
                if (_client != null) return _client;

                var httpClient = new HttpClient(new NativeMessageHandler { UseCookies = false, PreAuthenticate = true });
                httpClient.BaseAddress = new Uri(ApplicationSettings.BaseServiceUrl);
                httpClient.Timeout = TimeSpan.FromMilliseconds(45000);
                return _client = httpClient;
            }
        }

Suggest me any code for this to close this activity

Upvotes: 2

Views: 168

Answers (2)

Mohammad Zekrallah
Mohammad Zekrallah

Reputation: 449

In your caller (btnLoginClicked) or whatever, you need to handle Timeout exception or event that has been fired from your httpclient code timing out .. and then simply call Finish() in your catch clause .. if you don't seem to know how to catch a timeout raised from your HttpClient, maybe check this out : How can I tell when HttpClient has timed out?

Upvotes: 0

xleon
xleon

Reputation: 6365

Task.Factory.StartNew(async() => { await Task.Delay(45000); Finish(); });

Upvotes: 1

Related Questions