B btg1967 Member Licensed User Longtime User Jan 18, 2015 #1 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 Code: 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: Code: 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... Code: 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: Code: ** 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
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 Code: 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: Code: 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... Code: 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: Code: ** 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
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2015 #2 HttpJob.Download doesn't return any result. It starts an asynchronous download. You need to handle the result in JobDone. Upvote 0
HttpJob.Download doesn't return any result. It starts an asynchronous download. You need to handle the result in JobDone.
B btg1967 Member Licensed User Longtime User Jan 18, 2015 #3 Erel said: HttpJob.Download doesn't return any result. It starts an asynchronous download. You need to handle the result in JobDone. Click to expand... 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. Code: ** 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: Code: ** 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... Main -> Login Activity Login Activity, load layout Get local user fro the same class (works) Login sucess -> StartActivity(Main screen) Finish login activity 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
Erel said: HttpJob.Download doesn't return any result. It starts an asynchronous download. You need to handle the result in JobDone. Click to expand... 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. Code: ** 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: Code: ** 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... Main -> Login Activity Login Activity, load layout Get local user fro the same class (works) Login sucess -> StartActivity(Main screen) Finish login activity 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,
Erel B4X founder Staff member Licensed User Longtime User Jan 18, 2015 #4 The class context is the activity that initialized the class instance. The class will only handle events while its activity is in the foreground. In many cases the best (simplest) solution is to use a Service. Services are simpler to work with compared to activities as they are never paused. Upvote 0
The class context is the activity that initialized the class instance. The class will only handle events while its activity is in the foreground. In many cases the best (simplest) solution is to use a Service. Services are simpler to work with compared to activities as they are never paused.
B btg1967 Member Licensed User Longtime User Jan 24, 2015 #5 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: in Main, start the service, which initiates the class, and 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
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: in Main, start the service, which initiates the class, and 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...