The problem has nothing to do with my library but with your lack of knowledge of how multitasking works in Android. When a task runs in the background, which is the case when you set the asynchronous mode for ArchiverPlusZip, you cannot change the user interface directly (by changing a view property or displaying a dialog). You must call a sub with CallSubDelayed to make this change.
NOTE: Please don't take any of my posts as confrontational in any way. I am just confused and want to understand exactly what the issue is so I can be confident that when I release an app using this code, it will run reliably.
But even when I try using it in the default SYNCRONOUS mode (so then it is NOT running in the background?) and use the below separate event sub, it will still crash if I try to display a msgboxasync in the event sub:
Sub zip_ZipResult(Result As Int, ErrorMsg As String)
If Result <> Zip.ZIP_RESULT_SUCCESS Then
MsgboxAsync("There was an Error creating the ZIP file (" & ErrorMsg & ")","Zip Error")
Else
MsgboxAsync("ZIP file created ok!","Zip")
End If
End Sub
You're right, I don't know much about the innards of android multitasking, but I can sort of understand when you say that if I set it to ASYNCHRONOUS mode, the zip operation is running in another task (for performance reasons) so that my app can do other things, and until the background zip task finishes, I can't update the UI due to the multitasking. OK, that makes sense I guess.
But if I direct your lib to work in SYNCHRONOUS mode, why is it still triggering the ZipResult event when it appears a background zip operation/task is still running (because it will crash if I try to update the UI in the event sub)?
So, when I configure it for SYNCHRONOUS mode, why can't the event wait until the zip operation/task is actually fully completed (and accordingly the background task is fully finished) before it triggers so I can change the UI with it crashing?
Basically, if I can't update the UI because there is a background task running, then why doesn't SYNCHRONOUS mode fix this problem by not invoking the event until
after the background task is fully complete so it wont interfere with the UI thread anymore?
And lets say I want to email the zip file right after the Zip operation, do I still need to do a CallSubDelayed(Me, "Send-Email") to make sure the zip file is fully ready to be emailed and will not cause an error because the email program wasn't able to properly attach it to the email because the zip file was still open by the background zip task?
And is the CallSubDelayed solution 100% guaranteed to only run after the zip operation is
fully completed even for a
large zip operation?