Android Question HTTPJOB and Random crashes

FrankBerra

Active Member
Licensed User
Longtime User
Hi all,
my app is suffering from semi-random crashes caused by HTTPJOBS and i can't understand how to get out from the trouble

The codes that i use is like this one:

B4X:
Sub Process_Globals
Dim Pippo As HttpJob
End Sub

Sub Pippo_Sub
    Dim Pippo As HttpJob
    Pippo.Initialize("Pippo",Me)
    Pippo.PostString("https://xxxxx/test.php", "val1=" & val1 & "&val2=" & val2 & "&val3=" & val3)
End Sub

Sub JobDone (Job As HttpJob)
If Job.JobName="Pippo" Then
   If Job.Success = True Then
      Dim result As String
      result = Pippo.GetString
      ........
      .......
    End if
End If
End Sub

The Sub called Pippo_Sub is called multiple times by other portions of code so i followed advices on this forum to use "Dim Pippo" everythime i use the httpjob.
And also i removed (temporary) the instruction Pippo.Release

Everything works almost correctly but in some semi-random situations the app crashes with the error:
B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.io.FileNotFoundException: /data/user/0/test.app/cache: open failed: EISDIR (Is a directory)

With Semi-Random i mean that if i do some quick operations that probably call the Pippo_sub rapidly the app crashes always. If i do the same operation slowly everything works perfectly.

So is there an advice on how to use and reuse the same httpjob quickly without crashing the app?

Thanks in advance!
 

DonManfred

Expert
Licensed User
Longtime User
You should start removing Pippo from process_globals
Job.Release MUST be called when a job is done

What do you mean with "some quick operations"?
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
The Pippo_sub is called by clicking a button, so with "quick operations" i mean that i click the button twice in less than a second, for example.

As you suggested i removed declarations from process_globals and changed the sub JobDone accordingly and...WOW...no more crashes after months of headaches! Thank you @DonManfred

Regarding the Job.Release should i call it ONLY after job.success=TRUE or can i call it also if job.success=FALSE?
For example in the following code should i place Job.Release in Position 1 or in Position 2?

B4X:
Sub JobDone (Job AsHttpJob)
If Job.JobName="Pippo"Then
 If Job.Success = True Then
    Dim result AsString
    result = Pippo.GetString
    ........
    ........
  Job.Release 'Position 1 (Executed only if Job.Success = true)
  End if
Job.Release 'Position 2 (Executed even if Job.Success = false)
End If
End Sub

Thank you!
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just before the End Sub.

If you extend the if job.jobname with other checks the release will be working fine for all of them.

Also encapsulate the code with TRY/CATCH or your app might crash when time outs or other weirdness occurs.
 
Upvote 0
Top