Service

CharlesIPTI

Active Member
Licensed User
Longtime User
Service Revamped and Cleaned Where is the Code reentry

:BangHead::BangHead::BangHead:

Specifically HttpUtils Service-- I have given up on the Odd Custom way I was going to implement a Code module to interpret all of the web service calls. But I cant get "focus" back into my application MAIN after the HttpUtilService has done its work and updates a global variable exposed in process globals in my Main. the Flow is ..

Activity Main checks for First time.. If True it loads the login layout::

B4X:
Sub Activity_Create(FirstTime As Boolean)      
   HttpUtils.CallbackActivity = "Main"                        
   HttpUtils.CallbackJobDoneSub = "JobDone"
   HttpUtils.CallbackUrlDoneSub = "UrlDone"      
      If FirstTime Then
         Activity.LoadLayout("loginactivity")         
      Else
      
            If m_boolLoginSuccess = True Then
               StartActivity("postMain")
            Else
               Activity.Invalidate
            End If
            
      End If
End Sub

The Button Click for the login layout is handled in the Main Activity Module
it validates the user input a bit before calling another method
ValidateUser(m_strUzrNm) ::
which calls the HttpUtil stuff ::
HttpUtils.PostString("POST Job1", PostUrlLogin, "p_CartNumber=100&p_Login=" & userName)

The Http Util does its job nicely and the JobDone Sub in the Main Activity Module accompanied by the XmlSax Parser and its Subs again ALL in the Main Activity Module harvest my response from the Web Service beautifully and update the process Global boolean variable

B4X:
Sub JobDone (JobPassed As String)            
         parser.Initialize   
         Dim InputStream As InputStream
         Dim strRetVal As String                                 
            Select JobPassed            
               Case "POST Job1"      
               'Case "TryLogin"
                  If HttpUtils.IsSuccess(PostUrlLogin) Then                                        
                           InputStream = HttpUtils.GetInputStream (PostUrlLogin)   
                   Log(HttpUtils.GetString(PostUrlLogin))
                           Log(InputStream)                        
                   parser.Parse(InputStream, "Parser")               
                  Else                              
                  End If
            End Select                                                                                       
         'Turn off the complete flag so we won't handle it again if the activity is resumed.      
         HttpUtils.Complete = False          
End Sub



But heres where I'm confused.

If the method ValidateUser actually calls the HttpUtils ----- when the HttpUtils (JobDone & the Parsers) are finished where does the code focus go????

The Service (HttpUtil) calls Service_Destroy and just stops. It never "returns" to the calling Sub to do stuff with the value it has (in this case) harvested from the web service.


Where do I force-in the validation against the returned value and switch activities or invalidate the current and notify the user of their failure...


For example the MessageBox in this method is NEVER invoked ::


B4X:
Sub ValidateUser(userName As String)As Boolean      

      parser.Initialize

         '   HttpUtils.PostString("POST Job1", PostUrl, "p_CartNumber=45&p_Login=IPTI")
            HttpUtils.PostString("POST Job1", PostUrlLogin, "p_CartNumber=100&p_Login=" & userName)
            
            If m_boolLoginSuccess ==  True Then 
               Msgbox("Validation Value: "  &  m_boolLoginSuccess, "")            
            Else
            End If                
End Sub
 
Last edited:

CharlesIPTI

Active Member
Licensed User
Longtime User
Solved ???

I couldnt wait so I utilized the CHAT for B4A :) :sign0188: anyway
since my jobdone sub and the Sax Parsers ARE being called It was recommneded that I either add a CallSub to the Closing of the Service at Service_Destroy or call something to get back into my main from the Job Done.. I chose the Sax Parser EndElement since I was using that to actually harvest my data from the Web Service's returned response and flip my process global Boolean. I just added a call to Recall my activityCreate and I pass false. Since I was already conditioning that create method to fire up the secondary activity after login was successful, that handles my concern

FOR NOW

I Fear the multiple calls I will have to make to the web service will become quite the problem in the immediate future HOPE NOT !!!!

HotShoe and tds kinda helped me get to this point so thanks gentlemen oh and NJDude for just being there all the time thanks
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
The code under
B4X:
HttpUtils.PostString("POST Job1", PostUrlLogin, "p_CartNumber=100&p_Login=" & userName)
can never run as the code action is handed to the HttpUtils module. Once HttpUtils finishes it calls the CallbackActivity's JobDone sub, this is where you should validate and update your login boolean. The 'code focus' is much like any app until you click a button and raise an event the code is not doing anything. As HttpUtils calls a service once you have sent the Post request you can keep interacting with your UI until the JobDone is called.
 
Upvote 0
Top