Android Question How to cancel active Http requests

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

In some moment one activity starts another and dies.
But there is a problem with current downloads, which do not allow to die immediatelly.

I saw very old post with following sample

B4X:
   Dim reflectorInstance                                                        As Reflector

   reflectorInstance.Target = HttpUtils2Service.hc
   reflectorInstance.Target = reflectorInstance.GetField ("client")
   reflectorInstance.Target = reflectorInstance.RunMethod ("getConnectionManager")
   reflectorInstance.RunMethod ("shutdown")

where hc is HttpClient inside HttpUtils module.
Probably this works with OkHttpClient also.

But I am a little confused that httpClient.getConnectionManager() is deprecated.

What is correct method (I need a solution for API14+)
 

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, Erel --
Thanx for reply.
If you offer to transfer download from activity to service, it's not a good solution for me. First of all, because I have a lot "Wait For".

I made a small sample (attached). Run it and click "Start B" asap. Then wait.
"Wait for" after 10 seconds (timeout) activates main activity.
Meanwhile I want simply to forget about download and to kill main activity.

I attempted to change Http2Service (modified.zip). Changes are marked by *** My ***. To ignore previous http requests it's necessary to add statement
B4X:
    HttpUtils2Service.taskCounterMin = HttpUtils2Service.taskCounter
inside the activity.
It looks that works, but I am not sure that I released all resources. Can you look ?
 

Attachments

  • sample.zip
    11.5 KB · Views: 196
  • modified.zip
    11.6 KB · Views: 199
Last edited:
Upvote 0
Top