Android Question Loop bug? + Can't detect user Cancel in ExternalStorage

JohnC

Expert
Licensed User
Longtime User
Using the example in this post:

https://www.b4x.com/android/forum/threads/externalstorage-access-sd-cards-and-usb-sticks.90238/

I modified the PickFolder sub to include an "entry" log and an "exit" log tracing:

B4X:
Sub btnPickFolder_Click
    Log("Start SelectDir")
    Storage.SelectDir(chkUsePreviouslySelected.Checked)
    Wait For Storage_ExternalFolderAvailable
    Log("Exit from SelectDir")
  
    FoldersStack.Clear
    EnterFolder(Storage.Root)
End Sub

Now, if the user clicks the PickFolder button, the above code will log "Start SelectDir" and then invoke the method to display the devices "Folder browser".

However, if the user simply presses the back button on their device to abort (not) select a folder and dismiss the Folder Browser selector, the next line of code containing the "Log ("Exit from SelectDir") is never run, leading me to believe the Wait For Line of code is now stuck in an endless loop.

Ultimately, I need to detect if the user aborted the SelectDir action so my app can respond accordingly.

Any ideas?

Here is the log results when a user cancels the .SelectDir via the back button:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Start SelectDir
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
You could return a result from the 'wait for' called sub... Other than that, you give us too little info to help you...
Can you provide a project that exhibits this behaviour?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
As I mentioned, I am using the example at the provided link, which is a full project.

The only mods I made to it was adding the two "Log(xxx)" lines as mentioned.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, I modified the example to detect if the user presses the back button to abort the folder selection, and trigger the event so it won't stay in a loop.

The main change I did was to allow the event generator to return a null ExternalFile when the user aborts:

B4X:
Private Sub SetPickedDir(ReturnNull As Boolean)
    If ReturnNull = True Then
        Dim E As ExternalFile
        E.Initialize
        E.Name = ""
        Root = E
    Else
        Root = DocumentFileToExternalFile(GetPickedDir(PersistantUri))
    End If
    CallSubDelayed(mCallback, mEventName & "_ExternalFolderAvailable")
End Sub

Attached is the fully modified version of the example:
 

Attachments

  • ExternalStorage-AbortMod.zip
    12.2 KB · Views: 333
Upvote 0

agraham

Expert
Licensed User
Longtime User
Upvote 0
Top