Android Question Wait - not waiting

tsteward

Well-Known Member
Licensed User
Longtime User
Wait is not waiting so I guess i'm doing something wrong.
When my app loads it needs to check the database is present if not it must download it.

This is what I am trying. As soon as it hits the wait statement line 51 it returns to Activity_Create and doesn't wait

[CODE lang="b4x" highlight="51"] Activity.LoadLayout("Intro")

DBFileDir = rp.GetSafeDirDefaultExternal("") 'File.DirDefaultExternal

If FirstTime Then

If File.Exists(DBFileDir, "helper.db") = False Then

If Msgbox2("About to download the current Database 5.2mb?","Database Download","Yes","","Not Now",Null) = DialogResponse.POSITIVE Then

awake.KeepAlive(True)

ProgressDialogShow2("Please wait",False)



downloadDatabase



ProgressDialogHide

awake.ReleaseKeepAlive

Else

ToastMessageShow("Can't continue without database", True)

ExitApplication

End If

End If

End If

End Sub

Sub downloadDatabase

Dim j As HttpJob

j.Initialize("", Me)

j.Username = "XXXXXX"

j.Password = "XXXXX"

j.Download("https://www.XXXXX.com/Larastuff/helper.db")

Wait For (j) JobDone(j As HttpJob)

If j.Success Then

Dim out As OutputStream = File.OpenOutput(DBFileDir, "helper.db", False)

File.Copy2(j.GetInputStream, out)

out.Close '<------ very important

End If

End Sub[/CODE]
 
ok so I changed my code to:
But still returns without waiting

B4X:
    Activity.LoadLayout("Intro")
    DBFileDir = rp.GetSafeDirDefaultExternal("") 'File.DirDefaultExternal
    If FirstTime Then
        If File.Exists(DBFileDir, "helper.db") = False Then
            If Msgbox2("About to download the current Database 5.2mb?","Database Download","Yes","","Not Now",Null) = DialogResponse.POSITIVE Then
                awake.KeepAlive(True)
                ProgressDialogShow2("Please wait",False)

                Wait For(downloadDatabase) Complete (Result As Boolean)

                ProgressDialogHide
                awake.ReleaseKeepAlive
            Else
                ToastMessageShow("Can't continue without database", True)
                ExitApplication
            End If
        End If
    End If
End Sub

Sub downloadDatabase As ResumableSub
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Username = "XXXXXX"
    j.Password = "XXXXX"
    j.Download("https://www.XXXXX.com/Larastuff/helper.db")

    Wait For (j) JobDone(j As HttpJob)

    If j.Success Then
        Dim out As OutputStream = File.OpenOutput(DBFileDir, "helper.db", False)
        File.Copy2(j.GetInputStream, out)
        out.Close '<------ very important
    End If
    j.Release
    Return True
End Sub
 
Upvote 0
Activity_Resume will run before that.
This. I avoid using Wait For in activity create for that reason. Just because you pause activity create with wait for does not stop the application from going to the next stage(s) of Android’s application life cycle.
 
Upvote 0

Similar Threads

Replies
26
Views
17K
  • Locked
  • Article Article
Android Tutorial [B4X] SQL with Wait For
Replies
16
Views
42K
Replies
36
Views
136K
Replies
67
Views
137K
Back
Top