penduDev
penduDev

Reputation: 4795

How to cancel Google Cloud Endpoint Endpoint request

I'm using Google Cloud Endpoint Java api backend and connected Android application in android studio.

I'm making call to my backend api from the android app to check username availability.

username is checked on every text change event.

So when the text is updated, I want the previous request to be cancelled.

How do I achieve it?

One method I thought of was sending a random string with the request to server, and ignore all the received responses, except the latest. But this doesn't cancel the request, and network is still receiving the response. Also I have to send some extra data to keep track of requests.

So, how to cancel it? Is there any way to achieve it with google cloud endpoint api?

Additional info: I'm making google cloud endpoint request using an AsyncTask in android. I read something about cancelling the async task. Can that be used here somehow?

Upvotes: 1

Views: 125

Answers (1)

jirungaray
jirungaray

Reputation: 1674

Cancelling a request on the API is not a choice because it will most likely be processed and on the way back by the time your cancellation order reaches the server. Cancelling the Asynctask might be an option but you'll still have to account for threading and network latency hiccups.

I think the safest and easiest way is the one you already proposed, having a sequence added to your request and only update the UI if you receive the latest reply in the sequence.

Upvotes: 2

Related Questions