Android Question Set retryOnConnectionFailure to False

Jose Cuevas

Member
Licensed User
Longtime User
Hi, I've been having issues with silent retries when consuming a REST API using OkHttpUtils2, with poor cellular connections. And I saw that I can remove these retries by set retryOnConnectionFailure to False.

I found this tip from Erel https://www.b4x.com/android/forum/threads/mysql-problem.80538/post-510207, but I don't know where or how I should apply this code.

B4X:
'Replace the existing method in HttpUtils2Service
Sub Initialize
   If hc.IsInitialized = False Then
     TempFolder = File.DirTemp
     Dim jo As JavaObject = hc
     Dim builder As JavaObject = jo.RunMethod("sharedInit", Array("hc"))
     builder.RunMethod("retryOnConnectionFailure", Array(False))
     jo.SetField("client", builder.RunMethod("build", Null))     
     TaskIdToJob.Initialize
   End If
End Sub

I will appreciate any help you can give me.

Regards.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should never modify OkHttpUtils2 source. Instead follow this example: https://www.b4x.com/android/forum/t...edirections-with-okhttputils2.118469/#content
B4X:
Sub Service_Create
    Dim jo As JavaObject = HttpUtils2Service.hc
    Dim builder As JavaObject = jo.RunMethod("sharedInit", Array("hc"))
    builder.RunMethod("retryOnConnectionFailure", Array(False))
    jo.SetField("client", builder.RunMethod("build", Null))
End Sub

It doesn't need to be in the starter service if using B4XPages.
 
Upvote 0

Jose Cuevas

Member
Licensed User
Longtime User
Thank you Erel for your response. I followed your example, I added HU2_PUBLIC to the build configuration, I added the code to the Service_Create, but it gives me this error:

Unknown member: hc

2021-09-03_09h25_43.png


Regards,
 
Upvote 0

Jose Cuevas

Member
Licensed User
Longtime User
Ready, I just added HU2_PUBLIC in the Conditional Symbols and the error disappeared.

1630687346034.png


Thank you Erel
 
Upvote 0
Top