msgbox from service module

fotosettore

Member
Licensed User
Longtime User
hi !

is it possible to run a msgbox from a service ?

scenario : i run an app with a panel. this app has 1.bal and a service module running. when i exit from app, the service (naturally) is running . the 1.bal goes away.
so: i'd like to see a msgbox if (for example) service is destroied or inside it a string is changed.
i'ts ok to view the 1.bal again
i saw that from service is impossible any action about graphics.
is there a solution for it that is unknow to me ? may be a library ?
i'm new in b4a and so excuse me about this question
many thanks
 
Last edited:
I'm not a b4a "Veteran" but I think you'll have use a toast message, so if you're looking for actual yes/no response you might be sol, unless you want to pop up it via your activity in which case I think you'll need to use CallSubDelayed(Main, "YourSub"). In the sub you can maybe create a black/white panel and cover the whole screen, then hide it after your msgbox response. Probably need to use activity.finish also.

Something like this (un-tested)

Code:
dim APanel as panel
apanel.initialize("")
apanel.color=colors.black 'or colors.white, or whatever color your want!
activity.addview(apanel,0,0,100%x,100%y)
apanel.bringtofront 'just in case
dim MsgResponse as int
MsgResponse=msgbox2("Your question","Title","Yes","Cancel","No",null)
select case MsgResponse
case dialogresponse.positive
    callsubdelayed(AService,"ServiceYes")
case dialogrespone.negative
    callsubdelayed(AService,"ServiceNo")
case else
    Callsubdelayed2(AService,"MsgResponse",MsgResponse) 'or use a general one
end select
apanel.removeview
activity.finish

If you have a complex "main" activity, i.e. lots of loading/creating then you should probably just add a new activity to your project and use it to show a msgbox. Then you can probably skip the panel stuff cause you can just load your one panel layout or do it in the create sub.

Good Luck!
 
Upvote 0
many thanks for your reply
toastmessage is not good for my use : first, it disappears after 3 seconds; second, has not possibility of yes,no,continue.
as you said, i tried to use CallSubDelayed

this is my code of MAIN

Code:
Sub Process_Globals
    
End Sub

Sub Globals
   Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

   Activity.LoadLayout("1")
    Label1.text = "begin"
   StartService("test_serv")
   
End Sub

Sub SHOW_END

   Label1.Text = test_serv.DemoVar 
   Msgbox2("do you want to continue ?","Time End", "Yes","","No",Null)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

and this is my code in SERVICE
Code:
Sub Process_Globals
     Dim TimerTest As Timer
    Dim DemoVar As String=""
End Sub

Sub Service_Create

   TimerTest.Initialize ("TimerTest", 5 * 1000)
   TimerTest.Enabled = True
   
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub TimerTest_Tick

    DemoVar = "end"
    CallSubDelayed(Main,"SHOW_END")

End Sub

Sub Service_Destroy

End Sub

It runs ok if i'm inside app. But if i go out with back button, the msgbox does not appear and log says :

sending message to waiting queue (CallSubDelayed - SHOW_END)

where is my mistake ?
 
Upvote 0
many thanks erel
so please confirm me that the new sub code i post here (i tried, it runs) is really correct.

Code:
Sub TimerTest_Tick

    DemoVar = "end"
    StartActivity(Main)    ' <----- this is the add
    CallSubDelayed(Main,"SHOW_END")

End Sub
 
Upvote 0
Since you'll probably need to use startactivity, you might as well just put the msgbox call in the create and skip the callsubdelayed.
 
Upvote 0
Back
Top