Android Question ExternalStorage class. Blank screen after Wait For Storage_ExternalFolderAvailable

Juan Vargas (Bioagro)

Member
Licensed User
I have this segment, to make a backup into SD card.
It works fine, but after select the SD, while performing the backup, a blank screen remain visible.
I solved it inserting a DoEvents into the copy procedure. The device returns to the previous screen while performing the backup.
It is warned that doevents should not be used. But Sleep(0) doesn't do the job. Any alternative?

B4X:
Sub BtnBackupSD_Click
    Msgbox2Async("A Backup will be made into the device selected","Yes","Cancel","No", Null,False)
    Wait For Msgbox_Result (Result As Int)
    If Result <> DialogResponse.POSITIVE Then
        Return
    End If
    Storage.SelectDir(False)
    Wait For Storage_ExternalFolderAvailable
    Awake.KeepAlive(True)
    ProgressDialogShow2("Performing Backup",False)
    [B]PerformBackupSD [/B]' this is the procedure that copy the files, there I inserted a Doevents , Sleep(0) doesn't do the job[B][/B]
    MsgboxAsync (f.getlg("End Backup"),"Backup")
    Wait For msgbox_result
    Awake.ReleaseKeepAlive
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Juan Vargas (Bioagro)

Member
Licensed User
This is the procedure that copies the files. Its recursive.

B4X:
Private Sub CopyFoldertoSD(lxSource As String, lxSourceFile As String, lxDest As ExternalFile,lDirectorio As Boolean)
    Dim lFileName As String
    Private lFile As ExternalFile, lFolder As String
    Private fSD As ExternalFile, tmpSource As String, fDelete As ExternalFile
    tmpSource = lxSourceFile   
    If lDirectorio=True Then
        Try
            fSD=Storage.FindDirOrCreate(lxDest,tmpSource)
        Catch
            MsgboxAsync (f.getlg("Couldn't Backup in this location"),f.GetLg("Backup"))
            Wait For msgbox_result
            Return
        End Try
    Else
        fSD = lxDest   
    End If
    DoEvents
    For Each fex As String In File.ListFiles(lxSource)
        DoEvents
        If File.IsDirectory(lxSource, fex) Then
            lFolder = File.Combine(lxSource, fex)
            CopyFoldertoSD(lFolder,fex, fSD, True)
            Continue
        End If
        fDelete=Storage.FindFile(fSD,fex)
        If fDelete.IsInitialized Then
            Storage.DeleteFile(fDelete)
        End If
        LblBackupFecha5.Text=fex ' here a label shows the file name being copied
        Dim InputStream1 As InputStream
        InputStream1 = File.OpenInput(lxSource, fex)
        lFile=Storage.CreateNewFile(fSD,fex)
        Dim outputstream1 As OutputStream
        outputstream1= Storage.OpenOutputstream(lFile)
        File.copy2(InputStream1,outputstream1)
        InputStream1.Close
        outputstream1.close
    Next
End Sub
 
Upvote 0
Top