I need a small example in order to better understand it. Can't you use CallSubDelayed(Me, "RunAfterActivityCreate") in Activity_Create to call a sub that will run after Activity_Create?
Hi, example attached.
Log file looks like this
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Service (starter) Destroy **
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
SomeClassCode:Executing CallSub3SomeClassCode
TwoLevelClassCode:Executing CallSub3TwoLevelClassCode
TwoLevelClassCode:Called by CallSub3:1:2
End of activity_create
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy **
** Activity (main) Resume **
Attempt at simple explanation...
In Main:
Sub Process_Globals
Public pSomeClass As SomeClass
Public pTwoLevelClass As TwoLevelClass
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
pSomeClass.Initialize(Me, "SomeClassCode")
pTwoLevelClass.Initialize()
Log("End of activity_create")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub SomeClassCode(event As Int, str As String)
Log("SomeClassCode:"&event&":"&str)
End Sub
SomeClass
Sub Class_Globals
Public codeLocation As Object
Public codeName As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(subLocation As Object, subName As String)
codeLocation = subLocation
codeName = subName
Log(codeName&":Executing CallSub3"&codeName)
CallSub3(codeLocation, codeName, 1, "2")
End Sub
TwoLevelClass
Sub Class_Globals
Public pSomeClass As SomeClass
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize()
pSomeClass.Initialize(Me, "TwoLevelClassCode")
End Sub
Sub TwoLevelClassCode(event As Int, str As String)
Log("TwoLevelClassCode:Called by CallSub3:"&event&":"&str)
TwoLevelClass uses its own instance of SomeClass and initialises it with pointers to its own code.
SomeClass Initialise calls the given target code using CallSub3.
The target for the CallSub3(s) just identifies itself in the log.
From the log (and tracing) it can be seen that the CallSub3 in the "Main" SomeClass instance is not executed (no log entry) but,
the CallSub3 in the instance of SomeClass in TwoLevelClass is executed.
Execution seems to depend upon where the target code for the CallSub3 is located rather than just on the activity progress.
If it is in Main it is not called, if it is in a class it is called.
Your solution of using a general CallSubDelayed for initialisation would of course work as would replacing the CallSub3 with CallSubDelayed3.
I was attempting to increase the readability and consistency of my code when I encountered this anomaly.
Steve