How to cancel google cloud endpoints request in Android using the generated client library?

78 Views Asked by At

In the documentation it shows this example of how to execute a google cloud endpoints api request using the android client lib:

ScoreCollection scores = service.scores().list().execute();

Is there a way to cancel this request? I can't figure out how.

Sometimes I want to cancel long executing requests that I don't need anymore.

I know I could put it into a Thread of its own and cancel the thread, but that won't actually interrupt the .execute() method.

1

There are 1 best solutions below

2
On

There are some ways to do it:

  1. wrap each request in a Thread class and interrupt the thread (or take Runnable/Future/ExecutorService these classes are more useful), important note: you have check the interruption status in your code and then exit the task).
  2. try RxJava