Android Question Ho to realize a class for obtain a MsgBox usable from code in a module?

amorosik

Expert
Licensed User
"...The best solution is to use a class instead of a code module. You can then initialize the class in each of the activities. It will allow you to share more features between the activities..."
These are the word of Erel
The question is: how write a class to obtain a messagebox usable from code/service module?
For example, an app with 3 form and 1 module
When app start form1 is displayed, then operator press and go on form2, on module1 an sms is received and the code on module1 need to visualize a message
How write a class to display the messagebox and how instantiate it in form1, form2, form3?
 
Solution
To just show a MsgBox I think it's not needed to make a Class.
Try this.
It has a Service that every 5 seconds show a MsgBox.
It will show it on the currently displayed Page.

Sagenut

Expert
Licensed User
Longtime User
To just show a MsgBox I think it's not needed to make a Class.
Try this.
It has a Service that every 5 seconds show a MsgBox.
It will show it on the currently displayed Page.
 

Attachments

  • MSGBOX.zip
    15.4 KB · Views: 56
Upvote 0
Solution

amorosik

Expert
Licensed User
To just show a MsgBox I think it's not needed to make a Class.
Try this.
It has a Service that every 5 seconds show a MsgBox.
It will show it on the currently displayed Page.

The entire trick is the row
CallSubDelayed3(B4XPages.GetManager.GetTopPage.B4XPage, "ShowMessage", "FROM SERVICE", "WORK!!!")
that call a subroutine 'ShowMessage' on a form actually displayed
Timer is not needed
Perfect for me
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
If you dont click OK In the given example, after 5 seconds a 2nd MsgBox appears over the other one.
So, after 15 secs you have to click OK 3 times
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Timer was just to simulate some work from the service.
In your project the event will be raised every time that an SMS is received, if I understood correctly.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm interested about your post, why you think that a better approch is via service?
Exactly for wich reason?
I'm sure @Erel can explain why better than I can.

My general design approach is to put anything that deals with external input (e.g. async, database, SMS, telephony, etc.) inside services and then have the service raise events that activities can handle.
 
Upvote 0
Top