Hi I can not get my test app to call RefreshData in main activity when I get the expeted SMS.
The app will show the main activity but not execute RefreshData.
Am I doing something wrong with callsub?
B4X:
Sub smsint_MessageReceived (From As String, Body As String) As Boolean
If From = "+45XXXXXXXX" Then
ToastMessageShow(From & " - " & Body, True)
Main.SMSNumber = From
Main.SMSBody = Body
StartActivity(Main)
CallSub(Main, "RefreshData")
Return True
End If
End Sub
Try this code and see if it shows Main as Paused. You are calling the sub right after StartActivity(Main) and it may not be running yet.
B4X:
Sub smsint_MessageReceived (From As String, Body As String) As Boolean
If From = "+45XXXXXXXX" Then
ToastMessageShow(From & " - " & Body, True)
Main.SMSNumber = From
Main.SMSBody = Body
StartActivity(Main)
If IsPaused(Main) = False Then
CallSub(Main, "RefreshData")
Else
Msgbox("Main is Paused", "")
End If
Return True
End If
End Sub
Note that calling Msgbox from a Service will crash the application.
StartActivity sends a message to the message queue. When this message is processed the activity is started.
This means that if an activity is paused then calling StartActivity followed by CallSub will always fail. The activity will be paused at that time (unless it was not paused at all).
The best solution is:
B4X:
If IsPaused(Main) Then
StartActivity(Main)
RefreshDataFlag = True
Else
CallSub(Main, "RefreshData")
End If
'Main activity
Sub Activity_Resume
If ServiceModule.RefreshDataFlag = True Then
ServiceModule.RefreshDataFlag = False
RefreshData
End If
End Sub