Hi everyone.... I have a service module (SMS receiver) and once I have the right data I need it to pass it the Main activity.
Code in the service module.
B4X:
Sub ReceiverMobile(str As String)
CallSubDelayed2(Main,"MobileUpdate",str)
End Sub
Code in the Main
B4X:
Public Sub MobileUpdate(mbile As String)
Log("in the Main Activity ")
DBUtils.ExecuteMap(SQL, "Update profile set mobile = '"& mbile & "'",Null)
Log("Profile mobile updated! " & mbile)
End Sub
You neglected to say what exactly is not working. Are you not seeing the log statements? Is the app running in debug, release, obfuscated? We'll need a little more info to help you. If you're running obfuscated, try adding an underscore to the sub name and call (e.g. "Mobile_Update") and see if that fixes it.
I would recommend adding a log statement in your service before and after your CallDubDelayed2 to main to be sure the service is actually calling it.
Thanks everyone for giving the time. Yes I'm getting the data within the Receiver function.
This is the log output when a message arrived.
B4X:
[Address=+63977131xxx, Body=Testing number #+639994421xxx testing, IsInitialized=false
Code that receives the message
B4X:
Sub Service_Start(startingIntent As Intent)
Service.StartForeground(1, notification1)
servicerunning=True
Log("MessageInterceptor Service Started")
If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Dim MyValue() As String
Dim messages As List
Dim MessaGe,NewMobile As String
messages = ParseSmsIntent(startingIntent)
For i = 0 To messages.Size - 1
Log(">:"& messages.get(i))
MessaGe = messages.get(i)
Next
Dim startx As Int
Log(MessaGe)
startx = MessaGe.IndexOf("#")
NewMobile = MessaGe.SubString2(startx+1,(startx+1) + 13)
Log(NewMobile)
ReceiverMobile(NewMobile) '-----pass it to a function
End If
End Sub
I can pass it to another service module but can not in the Main activity.
The activity will not be started if the app is in the background.
You can start it yourself, however it is not recommended and will not work on Android 10+.
The correct way to notify the user is with a notification.