I ask for help to understand how to manage the need for a dialogue between a module with a class activity.
I mean, I've created a module-type activity to manage the interface and a class to implement its management (business logic).
I can not "pass" the object activity within the class to handle its members. as in C + +, I would like to pass a pointer \ reference class in generic class activity.
I hope I have explained clearly.
thanks
Private Sub Class_Globals
Private Callback As Object
Private Event As String
end sub
Public Sub Initialize(CallbackModule As Object, EventName As String)
Callback = CallbackModule
Event = EventName
you now have a reference to the activity in which this class-instance is initialized... And you have the eventname which should be fired in class...
So later in your class you then can use this to call a event in the calling activity with
B4X:
If SubExists(Callback,Event&"_UpdateComplete") Then
CallSub(Callback,Event&"_UpdateComplete")
End If
You can leave out the event-thing... and just use
B4X:
CallSub(Callback,"subname")
but it is probably always better to do a
SubExists-call first...
you can create a sub in activity and call this sub from your class.The sub has all permissions on using or changing members and properties
What exactly you want archieve?
For example, I have two members in the class activity: number and date
the generic class I would like to access the members of the class activity and manage the data of these members (variables or other objects).
So here in practice
after creating
Private mCallback As Object
Public Sub Initialize (CallbackModule As Object ...)
mCallback = CallbackModule
end sub
sub Test()
mCallback.Numero = xxx
mCallback.Data = yy
end sub
I think you have to make do with my cast the generic object or activity here does not work like that?!
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim myclass As mynewclass
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
myclass.Initialize(Me,"MNC")
End Sub
in mynewclass:
B4X:
Sub Class_Globals
Dim numero As Int = 0
Private Callback As Object
Private Event As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(CallbackModule As Object, EventName As String)
Callback = CallbackModule
Event = EventName
End Sub
'Gets or sets the numero
Sub getNumero As Int
Return numero
End Sub
Sub setNumero(i As Int)
numero = i
End Sub
You now can use
B4X:
Log(myclass.numero)
or
B4X:
myclass.numero = 35
to get or set numero in activity from the class...