I know that it is normally not possible for a code module to display a MsgBoxAsync from within one of the code module's routines because the MsgBox needs a UI context ie. Activity (I think that's the right terminology).
But, is there a way (ie. using some Java wizardry) to pass the Activity as one of the parameters to the code module routine so that the MsyBoxAsync can use it as the context?
I know that it is normally not possible for a code module to display a MsgBoxAsync from within one of the code module's routines because the MsgBox needs a UI context ie. Activity (I think that's the right terminology).
But, is there a way (ie. using some Java wizardry) to pass the Activity as one of the parameters to the code module routine so that the MsyBoxAsync can use it as the context?
yes, you can use a function in the code module by placing it with the ResumableSub return and calling the function using Wait For ...
see the example I set up
B4X:
'Activity Module Main ------
Sub Activity_Create(FirstTime As Boolean)
Wait For ( geral.calcular( 10.50 , 25.33 , 98.12 , 3.75 ) ) Complete (retorno As Double)
Log("retorno:"&retorno)
MsgboxAsync("Resultado: "&retorno&" correto?", "Atenção")
Wait For Msgbox_Result (result As Int)
If result = DialogResponse.POSITIVE Then' ok
MsgboxAsync("OK: "&retorno, "Msg")
Else
MsgboxAsync("OK: "&retorno, "Msg")
End If
End Sub
B4X:
'Code Module geral ------
Sub calcular(n1 As Double, n2 As Double, n3 As Double, n4 As Double) As ResumableSub
Dim retorno As Double = 0
If IsNumber(n1) Then retorno=retorno+n1
If IsNumber(n2) Then retorno=retorno+n2
If IsNumber(n3) Then retorno=retorno+n3
If IsNumber(n4) Then retorno=retorno+n4
Return retorno
End Sub
'Activity Module Main ------
Sub Activity_Create(FirstTime As Boolean)
geral.calcular2( "Main" , 10.50 , 25.33 , 98.12 , 3.75 )
End Sub
Sub mensagem_calculo(retorno As Double)
MsgboxAsync("Resultado: "&retorno&" correto?", "Atenção")
End Sub
B4X:
'Code Module geral ------
Sub calcular2( nome_modulo As String , n1 As Double, n2 As Double, n3 As Double, n4 As Double)
Dim retorno As Double = 0
If IsNumber(n1) Then retorno=retorno+n1
If IsNumber(n2) Then retorno=retorno+n2
If IsNumber(n3) Then retorno=retorno+n3
If IsNumber(n4) Then retorno=retorno+n4
Log("nome_modulo: "&nome_modulo&" | sub: mensagem_calculo | retorno: " & retorno)
CallSubDelayed2( nome_modulo , "mensagem_calculo" , retorno )
End Sub
'Activity Module Main ------
Sub Activity_Create(FirstTime As Boolean)
geral.calcular2( "Main" , 10.50 , 25.33 , 98.12 , 3.75 )
End Sub
Sub mensagem_calculo(retorno As Double)
MsgboxAsync("Resultado: "&retorno&" correto?", "Atenção")
End Sub
B4X:
'Code Module geral ------
Sub calcular2( nome_modulo As String , n1 As Double, n2 As Double, n3 As Double, n4 As Double)
Dim retorno As Double = 0
If IsNumber(n1) Then retorno=retorno+n1
If IsNumber(n2) Then retorno=retorno+n2
If IsNumber(n3) Then retorno=retorno+n3
If IsNumber(n4) Then retorno=retorno+n4
Log("nome_modulo: "&nome_modulo&" | sub: mensagem_calculo | retorno: " & retorno)
CallSubDelayed2( nome_modulo , "mensagem_calculo" , retorno )
End Sub
I very much appreciate your input, but even with your suggestion, the actual msgboxasync is located in an activity module.
What I was looking for was a way to have the MsgboxAsync in the Code module so it can be shared in different apps without having to place parts in an activity.
According to Erel, Here is an example using class to display MsgboxAsync.
I didn't know that in class I could post messages, it's new to me.
B4X:
'Activity Module Main ------
Sub Globals
Dim calc As calculo
End Sub
Sub Activity_Create(FirstTime As Boolean)
calc.Initialize
calc.calcular3(10.50 , 25.33 , 98.12 , 3.75)
End Sub
B4X:
'Code Class calculo ------
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
Sub calcular3( n1 As Double, n2 As Double, n3 As Double, n4 As Double)
Dim retorno As Double = 0
If IsNumber(n1) Then retorno=retorno+n1
If IsNumber(n2) Then retorno=retorno+n2
If IsNumber(n3) Then retorno=retorno+n3
If IsNumber(n4) Then retorno=retorno+n4
Log("retorno: " & retorno)
MsgboxAsync("Resultado: "&retorno&" correto?", "Atenção")
End Sub