Android Question Code never going to JobDone

malcfreem

Member
Licensed User
Longtime User
Hi.
I have an app and, when it starts up, I want to check that there is an Internet connection (either wifi or 3g). I used Erel's suggestion of downloading a web page. I put the code into a new project and it worked fine. When I ported the exact same code into my app's code, it never calls JobDone. Is it maybe because of the threads? The library references are identical in both projects

Here is a section of my code...


Sub Process_Globals

DimThread1AsThread'ignore => ignore warning of this line

DimThread2AsThread'ignore => ignore warning of this line

(etc)



Sub Activity_Create(FirstTime AsBoolean)

Dim job AsHttpJob

job.Initialize("j", Me)

job.Download("http://www.ladsbooks.co.uk/index.htm")

spinnerMap.initialize

Thread1.Initialise("Thread1")

Thread2.Initialise("Thread2")

File.Delete(File.DirInternal, "FDiOffers.db") ' only for testing

'check if the database already exists

IfFile.Exists(File.DirInternal, "FDiOffers.db") = FalseThen

'if not, initialize it

SQL1.Initialize(File.DirInternal, "FDiOffers.db", True)

'and create it

CreateDataBase

Else

'if yes, initialize it

SQL1.Initialize(File.DirInternal, "FDiOffers.db", True)

EndIf





Timer1.Initialize("Timer1",4000)

Timer2.Initialize("Timer2",300000)

Timer3.Initialize("Timer3",60000)

Timer1.Enabled=True

Timer2.Enabled=False

Timer3.Enabled=False

Activity.RemoveAllViews

svLay="BrowseRedeem"

Activity.LoadLayout(svLay)

End Sub





Sub JobDone(job AsHttpJob)

If job.Success Then

Msgbox("Connection","Yes")

Else

Msgbox("No connection","No")

EndIf

job.Release

End Sub
 

DonManfred

Expert
Licensed User
Longtime User
it never calls JobDone

That´s wrong. Your code can call the job and the job responses. It also shows the messagebox. But as you app reaches avtivity_resume your msgbox disappears...

If have change the msgbox to a output in LOG... This works fine
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
Hi DonManfred. No. I've had time to test your solution now. Yes, it works fine. But it also works fine when you change Log to Msgbox in the demo app you provided. But neither workwhen the code is put into my app with the above code. Neither Log nor msgbox. The code never seems to reach JobDone.
 
Upvote 0

Yalçın Kondur

Member
Licensed User
Longtime User
Try this one
B4X:
Sub Globals
    Dim xjob As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
    xjob.Initialize("Job1", Me)
    xjob.Download("http://www.google.com")
    ProgressDialogShow("Checking internet...")
End Sub

Sub JobDone(job As HttpJob) 
    If job.JobName="Job1" AND job.Success=False Then
        'Exit app if download failed
        ProgressDialogHide
        Msgbox("Sorry but this application needs internet.","Fail!")
        ExitApplication
    End If
    job.Release
    StartUp
End Sub

Sub StartUp
    ProgressDialogHide
    'All initialization things...
    Activity.LoadLayout("Layout1")
End Sub
 
Last edited:
Upvote 0

malcfreem

Member
Licensed User
Longtime User
Hi Yalcin. Nope. Code throws a compilation error caused by Dim job in globals. Moved the Dim to be the first statement in Create, but then the code never reachesJobDone. Simply sticks on 'checking internet...'.
 
Upvote 0

Yalçın Kondur

Member
Licensed User
Longtime User
job As HttpJob fails so i've changed it to xjob. tested, working ok.
---
today's lesson for myself: do not post any answer without testing
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
Can you upload your project (File - Export as zip)? Why are creating additional threads?
Hi Erel, Thank you for trying to help me.

I have tried that, but the zipped file is too big to upload (c.630k) and causes an error.
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
In case it helps, this is what appears in the log...

Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:FDi.Beta
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
startService: class anywheresoftware.b4a.samples.httputils2.httputils2service
sending message to waiting queue of uninitialized activity (submitjob)
Connected to B4A-Bridge (Wifi)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
 
Upvote 0

malcfreem

Member
Licensed User
Longtime User
Why are you creating additional threads?
Hi Erel.

To get the time from the time pool. I need to know the time in London, ie the time you will get if you stand outside Buckingham Palace and look at your watch (so including DST). This is regardless of the device time or timezone, which could be changed to manipulate offers.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…