Android Question Http2Utils not retrieving result?

btg1967

Member
Licensed User
Longtime User
Hi everyone,

I'm trying to get the result of this URL http://bot.whatismyipaddress.com/ which is a simple method to return the external IP address of a device.

There may well be an architectural/orchestration issue, but it's all just a bit strange, so if anyone has ideas, then I'm very happy to take advice.

Thanks in advance.

App starts in Main
B4X:
Sub Process_Globals
     Dim gThisDevice As modCLocalDevice
End Sub

Sub Activity_Create(FirstTime As Boolean)

    'Do not forget to load the layout file created with the visual designer.
    ProgressDialogShow("Initialising application")
    gThisDevice.Initialize
    StartActivity("modActLogin")
    Log("Welcome to " & Activity.Title)

End Sub

Here is my code for modCLocalDevice:
B4X:
Public Sub Initialize
       '... a whole bunch of initialization code, setting 
       'private variables to get the local user account and other
       ' boring stuff
    Log("Now Getting IP Addresses")
    GetMyExternalIPAddress 
End Sub
... further down in the class...
B4X:
Private Sub GetMyExternalIPAddress As String

Dim ThisReq As HttpJob
Dim sTarget = "http://bot.whatismyipaddress.com/" As String

    ThisReq.Initialize("ExtIP",Me)
    Log("XX: " & ThisReq.Download(sTarget))

End Sub
My log file reads like this:
B4X:
** Activity (main) Create, isFirst = true **
Now Getting IP Addresses
XX:
Welcome to <<My App Name>>
The JobDone code is in the Class definition for modCLocalDevice
 

btg1967

Member
Licensed User
Longtime User
HttpJob.Download doesn't return any result. It starts an asynchronous download. You need to handle the result in JobDone.
Hi Erel,

Thanks for the reply... That's sort of where I was going, and many posts here on the JobDone routine not being placed in the right activity context as I have also now got this in the log when I move JobDone to the Class module.
B4X:
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Object context is paused. Ignoring CallSubDelayed: JobDone
The JobDone is a Public method on the modCLocalDevice class and is doesn't appear to be being called at all.

I've also just noticed this:
B4X:
** Activity (main) Pause, UserClosed = false **
which seems to occur as a result of loading my Login screen...
So I'm a tad confused around the sequencing...
  1. Main -> Login Activity
  2. Login Activity, load layout
    • Get local user fro the same class (works)
  3. Login sucess -> StartActivity(Main screen)
    • Finish login activity
  4. Main screen activity, load the 2 line list controls with the information I'm after...
I'm certain this is probably a simple error on my part, but I just can't see it (yet),

Thanks again,
 
Upvote 0

btg1967

Member
Licensed User
Longtime User
Thanks Erel, I still am feeling like a bit of a newb ... these seem like silly mistakes, so thank you for your patience and assistance. It's very much appreciated - I promise to start few rippers in the net few posts...

OK - so now I'm trying to look at how to refactor my design a bit.

I have a class that I'd like to be populating on start-up, and then refer to throughout the app lifetime.

What seems to be the best approach (for asynchronous objects - populated by web service) is:
  1. in Main, start the service,
  2. which initiates the class, and
  3. then expose the class object off the service?
    • so rather than main.<<class instance>>, instead
    • use <<service name>>.<<class instance>>
This is now working a treat, although the emulator provides a few interesting responses to 'standard' calls...
 
Upvote 0
Top