Try Again, strange behaviour

elck

Member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
   Activity.LoadLayout("screen")
   Dim result As Int
   If TestConnectivity=False Then
      result=Msgbox2("no internet, try again?", "Problem","Yes","","No",Null)
      If result = DialogResponse.Positive Then StartActivity("choose")    
      If result = DialogResponse.NEGATIVE Then Activity.finish
      
   End If
   job1.Initialize("Job1", Me)
        job1.Download("http://www.google.com")
End Sub
sub TestConnectivity
   return false //just for testing dummy sub
end sub
Now, when I press 'Yes' sometimes activity 'choose' starts as predicted, but sometimes the current activity (which btw is 'choose') continues with the http job.
What is my mistake please?
 

Kevin

Well-Known Member
Licensed User
Longtime User
I don't know if this is your problem or not but you might want to add a Return like so:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("screen")
    Dim result As Int
    If TestConnectivity=False Then
        result=Msgbox2("no internet, try again?", "Problem","Yes","","No",Null)
        If result = DialogResponse.Positive Then StartActivity("choose")     
        If result = DialogResponse.NEGATIVE Then Activity.finish
        Return ' <---- New
    End If
    job1.Initialize("Job1", Me)
        job1.Download("http://www.google.com")
End Sub
sub TestConnectivity
   return false //just for testing dummy sub
end sub


Perhaps it makes no difference, but I don't know if you'd want to repeatedly start the activity over and over or maybe move that to a sub that you call over and over. I would think starting the same activity over and over might be overkill, but may be harmless.

I do think the Return statement above will help your other problem though.
 
Upvote 0

elck

Member
Licensed User
Longtime User
Thanks Kevin,
The 'return' did not do the trick, but moving to and restarting a sub did.
Thanks, I should have seen that myself.
 
Upvote 0
Top