I'm revisiting my Push Library I was working on some time ago. I "quit" because I was having an issue raising events when the activity holding the class instance was not "active". I'm starting to make some progress however when I try StartActivity(Main) from within the class it doesn't work like it does from within a service.
Here's my service code:
Here's my Class Code which ultimately raises the event:
Also, is there a way to call a code module sub without knowing the sub before hand? For example, in this situation, we may not always want the activity to become active, which would be the only way to run the "event" code. I'd like to pass a "code modules" sub to the class instance to be called upon a message. For example:
Then within the class's "MessageReceived" routine I can call the sub:
CodeToCallOnMessage(data)
Here's my service code:
B4X:
Sub MessageArrived (Intent As Intent)
Dim From, CollapseKey, data As String 'ignore
If Intent.HasExtra("from") Then From = Intent.GetExtra("from")
If Intent.HasExtra("data") Then data = Intent.GetExtra("data")
If Intent.HasExtra("collapse_key") Then CollapseKey = Intent.GetExtra("collapse_key")
For Each aPush As Push In PushGlobals.PushList
If aPush.ProjectID=From Then
StartActivity(apush.Activity) 'THIS WORKS
aPush.MessageRecieved(data)
Exit
End If
Next
End Sub
Here's my Class Code which ultimately raises the event:
B4X:
Sub MessageRecieved(data As String)
'raise an event
If SubExists(target,Event & "_" & "Message") Then
StartActivity(Activity) 'THIS DOES NOT WORK
CallSubDelayed2(target,Event & "_" & "Message",data)
End If
End Sub
Also, is there a way to call a code module sub without knowing the sub before hand? For example, in this situation, we may not always want the activity to become active, which would be the only way to run the "event" code. I'd like to pass a "code modules" sub to the class instance to be called upon a message. For example:
B4X:
Dim APush as Push
APush.CodeToCallOnMessage="Globals.MyPush"
Then within the class's "MessageReceived" routine I can call the sub:
CodeToCallOnMessage(data)