How to build up the program

JDS

Active Member
Licensed User
Longtime User
Morning,

I'm building a new application but now i'm not sure how to continue.

The user has to go step by step (screen by screen) through a specific path with an array of data. At the end of the path the user has to aquire a signature and save it to disk. Then it is send to the server and then the user has to go back to step one.

What is the best way to build up the program? At this point i've build multiple layouts and activities, every step is a new activity and layout. After signing i send the file to the server and i clear the array. On every activity resume i check if the arraysize is zero. If so than i call activity.finish.
Is this the right way?

Sending the signature is at activity "X" (with a jobdone). But when the server isn't reached the signature isn't send to the server but remains on disk. To resend all signatures on disk there is a button in activty/layout "A". But this means that i have two places with a jobdone.

-----------------


The other problem is the data which the user has to work with. If the app starts it looks for an XML-file and reads it with Saxparser, al working. This happens at activity "B"
But when there is no XML-file the user has to retreive an XML-file from the server. This is at activity "T" but for reading the xml with the Saxparser i've to add again the parsing-code and the "_endelement"-sub..


----------------------

Should i use:
- 1 activity with multiple layouts
the pro is that i can use 1 jobdone and 1 _endelement-sub for parsing the code. The con is that i have one gigantic file with code

- multiple activities and layouts
the pro is that i have my code better viewable. the con is that i have multiple pieces of code which are exactly the same (which is more work to do work with / keep in sync.) (i was thinking of the parsing and the jobdone)
 

Penko

Active Member
Licensed User
Longtime User
Regarding the event catch in the two activities, why don't you isolate your code in a code module(the part which makes the communication to the server and the other which handles the xml)? In the two activities you will merely call the corresponding Subs from the code module. I will give you another example - I have a code module Admober and in my activities, I only catch the three events and call the corresponding subs with a reference to the Activity, if needed. This makes the change to the ads behavior a piece of cake.

Splicing different layouts into different activities is always a better option but you may also use Tabhost for these steps. But you have to protect the access to next steps if the current one is not complete.

Sent from my HTC Desire using Tapatalk
 
Upvote 0

JDS

Active Member
Licensed User
Longtime User
I've tried the above by putting my communication in a Code Module called "Globaal".
If I call/try:

B4X:
Sub RouteCall
   Dim requestSoapXML As String
   Dim sChar As String
   Dim Soap As HttpJob
   Log("in route call")
   sChar = "&"
   Soap.Initialize("GetRoute","Globaal")
   HttpUtils.CallbackUrlDoneSub = "" 'don't want to handle this event
   requestSoapXML = Main.MainUrl&"/GetRoute10/JSON?iPDA="&Main.uniqueID&sChar&"sWachtwoord="&Main.wachtwoord&sChar&"xmlParameters="
    Log(requestSoapXML )
    Soap.Download(requestSoapXML)
End Sub

the programm doesn't reach the JobDone sub which is in the same codemodule.

B4X:
Sub JobDone(Job As HttpJob)
   Dim sResult As String
   Dim I As Int
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   
   If Job.Success = True Then
        Select Job.JobName
         Case "GetRoute"
            sResult = Job.GetString
            If (sResult.Trim<>"" AND sResult.Contains("</b>")) Then
               Log("GetRoute succes")
               Route_Verwerken(sResult)
            Else 
               Log("GetRoute failed")
            End If
         
         
      End Select
   Else
      Log("Error: " & Job.ErrorMessage)
   
   End If
   HttpUtils.Complete = False
End Sub

I've tried

B4X:
soap.initialize("GetRoute",me)
But that ain't allowed in a code module.

When I had the same code (RouteCall and JobDone) in a Activity module it worked.
But I need to call the sub RouteCall at multiple places (and also others).

Therefor I would like to place the communication and XML-parsing in one global package.
 
Last edited:
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Hello JDS,

I meant something like this:

Code Module Globaal
B4X:
Sub JobDone(Job As HttpJob)

' download file

' parse xml

' split in more Subs for better readability

End Sub

Activity1
B4X:
Sub HTTP_JobDone(Job As HttpJob) 
Globaal.JobDone(Job) ' call the subroutine in the Code Module
End Sub

Activity2
B4X:
Sub HTTP_JobDone(Job As HttpJob) 
Globaal.JobDone(Job) ' call the subroutine in the Code Module
End Sub

Activity3
B4X:
Sub HTTP_JobDone(Job As HttpJob) 
Globaal.JobDone(Job) ' call the subroutine in the Code Module
End Sub

Remember: You can handle events only in Activity modules + Class module(because they share the calling Activity's life cycle). Services also handle events themselves. That's why you haven't managed to catch the event in the code module, it's impossible.

The idea is to isolate your logic in the Code Module and then in Activities, only handle the event and call the Sub.
 
Upvote 0
Top