Android Question aPOI (jPOI for Android) with ProgressDialog

kgcarpenter

Member
Licensed User
I have an app that will compile an xlsx file.
The process of creating and saving the file takes about 20 seconds.

Currently I am trying to implement a Progress Dialog so the end user can see something is happening.
I hoped it would be something as simple as adding
B4X:
ProgressDialogShow2("Please Wait", False)
before the aPOI code.

Unfortunately the ProgressDialog only starts after the xlsx file has finished saving, and so only shows for a second.
What would be the best way to implement the Dialog so it starts when the user clicks save and finishes once the file is saved?

I have attached a small sample of the aPOI code.
B4X:
        Dim row As XSSFRow = sheet.getRow(41)
        Dim Cell As XSSFCell = row.getCell(2)
        Cell.StringCellValue = ACEditText1.Text
        
        Dim row As XSSFRow = sheet.getRow(42)
        Dim Cell As XSSFCell = row.getCell(5)
        Cell.StringCellValue = DateText.Text
        
        
        
        
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
        wait for Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
        
            Dim outstream As OutputStream = File.OpenOutput(File.DirRootExternal, "Vehicle Checks Completed.xlsx", False)
            xls.write(outstream)
            outstream.close
 

Erel

Administrator
Staff member
Licensed User
Upvote 0

kgcarpenter

Member
Licensed User
The problem is that xls.Write is a blocking method. It will hold the main thread until it completes and you will not be able to show any UI. It can also cause the app to crash with the ANR dialog.

The best solution is to update the library and add an async version using BA,runAsync: https://www.b4x.com/android/forum/threads/java-libraries-and-multithreading.12697/post-204943
Okay thanks.

I think libraries are possibly beyond my understanding currently, I'll have to start learning and hope DonManfred updates his library first 😂
 
Upvote 0

DonManfred

Expert
Licensed User
I see. I´ll investigate
 
Upvote 0

DonManfred

Expert
Licensed User
I'll have to start learning and hope DonManfred updates his library first

Try it with this Version.

B4X:
    Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    wait for Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        xls.write2(File.DirRootExternal,"excelout.xlsx")
    End If
B4X:
Sub XLS_written(success As Boolean, Info As String)
    Log($"XLS_written(${success}, ${Info})"$)
End Sub
 

Attachments

  • aPOIV0.11.zip
    24.6 KB · Views: 127
Upvote 0

DonManfred

Expert
Licensed User
however the sub xls_written is never triggered.
It depends on the event-prefix you set when initializing.

Change it from "" to "xls"

B4X:
    xls.Initialize("XLS",File.Combine(File.DirInternal,"qqq.xlsx"))
 
Last edited:
Upvote 0
Top