Reputation: 16110
I am looking for a more complete library that will enable me to cancel long running http requests (example file upload which is at least 100 MB of data).
I have seen Volley which provides a cancelation API but it seems that it just handles not calling the callback and not actually stopping execution (i might be wrong on this) also its not recommended for long running request.
I have also been looking at ION https://github.com/koush/ion which is supposedly able to handle cancelation due to it returning a future task which you can cancel, but i don't really know if this is the right choice for my case. I don't want the requests to run in parallel, but rather in sequence.
I have also written such a library myself (https://github.com/darko1002001/android-rest-client) which i have been using for a long time now and has been working great, i have done some workarounds to fit in a cancelation of requests and progress updates for some cases that i've had, but to be honest i don't really feel that it is clean or robust enough for this requirement.
I typically use a threadpool for the request execution but move long running request in a single thread pool queue so that other short requests are still executed without being blocked but the long operation. I feel that my workaround is better if i have to still manage request execution on my own to be sequential for the long running requests.
Can someone share his/her experiences in building such a feature? any suggestions/recommendations on what to use?
Upvotes: 0
Views: 321
Reputation: 3104
I have been using AsyncHttpClient
it supports cancel method , you can find detail in doc
Upvotes: 0
Reputation: 2563
For downloads, consider using the Android Download Manager. It is simple to use and the user can cancel at any time.
For Uploads You could use a Wakefull Service and do the upload yourself. HTTP uploads are not dramatically complicated so I'd just go with this. Depending on Android Version either use the Apache HTTP lib (pre 2.3.3) or HTTPUrlconnection (everything newer). also note that the volley code is open source and you can borrow their upload logic (or parts thereof) :)
Upvotes: 1