Android Question Trying to pass data from service to Main activity.

microbox

Active Member
Licensed User
Longtime User
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

Sorry if this is easy but I can't make it work.
 
Last edited:

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

microbox

Active Member
Licensed User
Longtime User
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.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…