Android Question Use Httpjob to build your own B4A library

Hi,
I want to create a library using the standard class where a file should be downloaded, so I decide to use httpjob in my library, but I do not know how to initialize httpjob because by giving Me the target input in the class, the force program will close. Give.
Please help. Thankful
 
can you post your code? or maybe a simple example that demonstrates what you are doing? it will be simpler to help you
here you are.
In fact, my intention is to build a library in which a download can be made.
Please check the attached sample and describe the solution.
Thankful
 

Attachments

ilan

Expert
Licensed User
your mistake is in this line

B4X:
    Wait For (j) JobDone(j As HttpJob)
you declare at the top the httpJob as "http" so you need to wait when "http" is executed and not if j (that is the response httpjob)

just change this line to:

B4X:
Wait For (http) JobDone(j As HttpJob)
 
your mistake is in this line

B4X:
    Wait For (j) JobDone(j As HttpJob)
you declare at the top the httpJob as "http" so you need to wait when "http" is executed and not if j (that is the response httpjob)

just change this line to:

B4X:
Wait For (http) JobDone(j As HttpJob)
Yes, you are right, but I also changed this line, but force close still occurs.
I think in a standard class "Me" can not be given as a Target to httpjob.
 

ilan

Expert
Licensed User
why are you changing the standard b4a context?

the error you get is very clear:
Error description: Initialize sub cannot be resumable.
change your class to this:

B4X:
Public Sub initialize
    download
End Sub

Public Sub download
    Private http As HttpJob
    http.Initialize("http",Me)
    http.Download("https://cdn.shortpixel.ai/client/q_glossy,ret_img/https://www.b4x.com/basic4android/images/dopus_NucbTJkLV0.png")
   
    Wait For (http) JobDone(j As HttpJob)
    If j.Success Then
        Log("yes")
    Else
        Log("no")
    End If
    j.Release
End Sub
call the class like this:

B4X:
    Private a As MyLibrary
    a.initialize
 

ilan

Expert
Licensed User
why are you changing the standard b4a context?

the error you get is very clear:


change your class to this:

B4X:
Public Sub initialize
    download
End Sub

Public Sub download
    Private http As HttpJob
    http.Initialize("http",Me)
    http.Download("https://cdn.shortpixel.ai/client/q_glossy,ret_img/https://www.b4x.com/basic4android/images/dopus_NucbTJkLV0.png")
  
    Wait For (http) JobDone(j As HttpJob)
    If j.Success Then
        Log("yes")
    Else
        Log("no")
    End If
    j.Release
End Sub
call the class like this:

B4X:
    Private a As MyLibrary
    a.initialize
God bless you. My problem was solved.
Thank you as well as Earl
 
Top