Android Question Msgbox and Msgbox2

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

My apologies for starting this new thread since I have a similar thread on this subject. I guess I was not clear in my previous thread on the subject.

PROBLEM
When I use Msgbox or Msgbox2, they do not behave as modal. If I click anywhere outside the Msgbox, the Msgbox disappears - thus, behavior is non-modal.

ILLUSTRATION
I wrote a small app to illustrate the issue and filmed (definitely not Oscar material, but there may be an award for worst film...). The youtube video shows the program execution first on a Nexus 10 V4.4.4 and second on an ASUS Memopad V4,2. In both tablets, the behavior of the Msgbox2 is not modal.

First, the video


Second, the code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Panel1.SetLayout(0,0,100%x,100%y)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
    If Action=Panel1.ACTION_DOWN Then
        Label1.Text="Panel Touched."
        Panel1.Color=Colors.Red
    End If
End Sub

Sub Button1_Click
    Label1.Text="TRY AGAIN"
    Dim nresp As Int
    nresp=Msgbox2("Click Yes for BLUE and No for GREEN","","YES","","NO",Null)
    If nresp=DialogResponse.POSITIVE Then Panel1.Color=Colors.Blue
    If nresp=DialogResponse.NEGATIVE Then Panel1.Color=Colors.Green
End Sub

Any and all help will be truly welcomed.

Thank you.

Sandy

Original Thread:
http://www.b4x.com/android/forum/threads/msgbox-and-msgbox2-modal.44945/#post-275461
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
And @Erel already answered this here
This is how dialogs in android works.

I suggest using the Floating Windows-Library.

Hello, and thank you, Don.

I may be missing the point BIG TIME. Erel said:

The dialogs are modal because the code waits until the dialog is dismissed.

The dialog is dismissed when I touch the panel in my example. Would that not be be non modal behavior? Or what is non-modal behavior?

I thought the definition of modal was:

A modal dialog box requires the user to close the dialog box before activating another window in the application.

...which is what Erel is saying but it is not what is happening. Did you take a look at the short video?

I just ran the same app in a Samsung Note V4.4.2 and it does show modal behavior. Here is the clip:


Don, Erel, I need your help. Please take a look at the videos of the same app.

The first video: Nexus 10 V4.4.4 and second on an ASUS Memopad V4.2 - behavior is non modal.
The second video: Samsung Note V4.4.2 - behavior is modal.

Thank you in advance and forgive my insistence and persistence on this matter. I am more of a pragmatist than an academic and will readily accept workarounds. In this case, the inconsistency in 3 mainstream tablets with Android 4.+ baffles me.

Best regards.

Sandy
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

I did additional research since I was having a mental block with this issue of the modal Msgbox.

According to Android,
I work on the Android framework team and we've specifically designed the framework to not have modal dialogs that block the current execution thread. I know how it could be done but it's not the model we chose for Android. – Romain Guy Sep 27 '13 at 18:41

The discussion is heated related to the topic. In the same thread:
Please note that the OP certainly didn't want to actually stop the UI thread, just wanted to block the user workflow. Since that's a valid and common use case (as users hardly ever perform multiple parallel interactions with their gadgets, and systems commonly need to wait for them), it's natural to expect some trivial modal dialog API seamlessly matching the "single-threaded user" reality. It's understandable if it's not easy to do nicely. But if the Android team could come up with a smart way to make it as trivial as illustrated in the question, it could only help us all. Thx! – Sz. Jan 12 at 13:12

The thread is at:
http://stackoverflow.com/questions/...-block-execution-while-dialog-is-up-net-style

However, I will attest that Samsung seems to have done something about it. Both in the Samsung Note 10 and the S3, the Msgbox behave as modal - stop the code until an answer is received.

I apologize for my insistence because of the inconsistencies that I was experiencing in different devices. Erel's original response affirmed by Don was precise: DialogResponse.Cancel is received if the user dismisses the dialog.

Thank you, Don and Erel.

Sandy
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
Note that modal dialogs is a unique feature of B4A. There are no native modal dialogs in Android (or Samsung).

Thank you, Erel.

I think I got a handle on this feature at this point.

Best regards.

Sandy
 
Upvote 0

JTmartins

Active Member
Licensed User
Longtime User
This is what I use to prevent that situation, and if you press outside the dialogue it will pop up again.

B4X:
Private reply As Int=-3
  
Do While reply = -3
reply=Msgbox2("Whatever message you want","Confirm ?", "yes","","No",LoadBitmap (File.DirAssets, "xxx.png"))
     If reply=DialogResponse.POSITIVE Then
         whatever you want
     else
        whatever you want
     end if
loop
 
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
This is what I use to prevent that situation, and if you press outside the dialogue it will pop up again.

B4X:
Private reply As Int=-3
 
Do While reply = -3
reply=Msgbox2("Whatever message you want","Confirm ?", "yes","","No",LoadBitmap (File.DirAssets, "xxx.png"))
     If reply=DialogResponse.POSITIVE Then
         whatever you want
     else
        whatever you want
     end if
loop

Thank you, JT. Clever and succinct code. However, the else in your code will capture the -2 and the -3 reply. You cannot have an ELSE. I recoded your routine:

B4X:
Private reply As Int=-3
 
Do While reply = -3
reply=Msgbox2("Whatever message you want","Confirm ?", "yes","","No",Null)
     If reply=DialogResponse.POSITIVE Then Panel1.Color=Colors.Blue
     If reply=DialogResponse.NEGATIVE Then Panel1.Color=Colors.Green
      Log (reply)
Loop

Erel had suggested the same process, but you provided the code... Erel's post:

http://www.b4x.com/android/forum/threads/msgbox-and-msgbox2-modal.44945/#post-275214

(One day, I will learn how to convert the hyperlink to "here")

I tested it and your code also persists if the back arrow is pressed...

Best regards.

Sandy
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Thank you, JT. Clever and succinct code. However, the else in your code will capture the -2 and the -3 reply. You cannot have an ELSE. I recoded your routine:

B4X:
Private reply As Int=-3

Do While reply = -3
reply=Msgbox2("Whatever message you want","Confirm ?", "yes","","No",Null)
     If reply=DialogResponse.POSITIVE Then Panel1.Color=Colors.Blue
     If reply=DialogResponse.NEGATIVE Then Panel1.Color=Colors.Green
      Log (reply)
Loop

Erel had suggested the same process, but you provided the code... Erel's post:

http://www.b4x.com/android/forum/threads/msgbox-and-msgbox2-modal.44945/#post-275214

(One day, I will learn how to convert the hyperlink to "here")

I tested it and your code also persists if the back arrow is pressed...

Best regards.

Sandy


In this case it is probably better to put the full link visible, so we see that the thread is the same (or #2 as link)

However, to use the "Here", select the word and click the icon that represents two links of a chain.

upload_2014-9-25_4-24-50.png
 
Last edited:
Upvote 0

tdocs2

Well-Known Member
Licensed User
Longtime User
you are right Tdocs

I typed quickly to reply and did not check. Sorry for my mistake.

Well, JT, I am very glad that you typed at all. You were trying to help me and the community by sharing your knowledge, and that, I think is the spirit and intent of this forum.

It is a good solution that addresses the
"single-threaded user" reality

Best regards.

Sandy
 
Upvote 0
Top