help then starting an activity from a service.

kent

Member
Licensed User
Longtime User
In service:
B4X:
If Main.tilstand=0 Then 
StartActivity(Main)
End If
            
CallSub2(Main,"spil_lyd","besked.mp3")
CallSub2(Main,"msg",param)

The two subs from main:

Sub msg (besked As String)
Msgbox(besked,"Besked fra HOS")
End Sub

Sub spil_lyd(mp3 As String)
   MP.Initialize
   MP.Load(File.DirAssets, mp3)
   MP.Play 
End Sub
The scenario is:

A sub in my service shall play a sound and show a test message in a msgbox.

The service can´t do that, so I make it happen via two subs in the “Activity main”

Is the activity paused, then it is started via the sub in the service.

The code works fine if the activity is running, but if it is paused, then it seems like the activity is just started and the call of the two subs “msg” and “spil_mp3” afterwards is not working.

If I call the sub in the service again after it has started the activity the first time, then it works fine.

The service is running all the time – but it works like it exits the sub that is calling the “start” of the activity.
Am I doing something wrong or/and is there a better way to do it ?

Best regards
Kent
 
Last edited by a moderator:
Top