iOS Question doEvents / async methods

Albi

Active Member
Licensed User
Longtime User
Hello,
I know I've asked this before but I obviously don't understand it fully as I can't seem to get messages to run at the right time.

I want the first message to show, then the code to run, then the 2nd message to show.
B4X:
Sub btnShare_Click
    HD.ToastMessageShow("Exporting...", False)
    UploadFiles
End Sub

Sub UploadFiles
For n = 0To clvPics.GetSize - 1
Dim pnl AsPanel
 pnl = clvPics.GetPanel(n)
 img1.Initialize("")
 img1 = pnl.GetView(0)
 phoneSave.AddImageToAlbum(img1.Bitmap)
Next
HD.ToastMessageShow("Images exported", False)
End Sub
At the moment it runs very fast, but if i have lots of images, or want to export to somewhere other than the camera roll it will be slower. Currently, the first message and the second message show at the same time.
I tried
B4X:
callsubdelayed(Me, UploadFiles)
in btnShare_Click but that made no difference. I also tried putting the messages into their own sub and calling them delayed but that also didn't help.
Sorry for a repeat question, and thanks for any help
 

narek adonts

Well-Known Member
Licensed User
Longtime User
I Think this is the best solution

B4X:
Sub btnShare_Click
    HD.ToastMessageShow("Exporting...", False)
    UploadFiles
End Sub

Sub UploadFiles
For n = 0To clvPics.GetSize - 1
CallSubDelayed2(Me,"UploadFiles2",n)
Next
HD.ToastMessageShow("Images exported", False)
End Sub

Sub UploadFiles2(n as int)
Dim pnl AsPanel
pnl = clvPics.GetPanel(n)
img1.Initialize("")
img1 = pnl.GetView(0)
phoneSave.AddImageToAlbum(img1.Bitmap)
End sub
 
Upvote 0

Albi

Active Member
Licensed User
Longtime User
thanks, that kind of worked. The 'images exported' message shows over the other one, and they both appear during the duration of the export, so i've just used the 'exporting...' message which now disappears as soon as the export stops which is perfect, except I don't understand why it works.
 
Last edited:
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
I think it's just a coansidance.

try this to get start and end.

B4X:
Sub btnShare_Click
    HD.ToastMessageShow("Exporting...", False)
    UploadFiles
End Sub

Sub UploadFiles
For n = 0To clvPics.GetSize - 1
CallSubDelayed2(Me,"UploadFiles2",n)
Next

End Sub

Sub UploadFiles2(n as int)
Dim pnl AsPanel
pnl = clvPics.GetPanel(n)
img1.Initialize("")
img1 = pnl.GetView(0)
phoneSave.AddImageToAlbum(img1.Bitmap)
If n=clvPics.GetSize-1 then
HD.ToastMessageShow("Images exported", False)
end if
End sub
 
Upvote 0

Albi

Active Member
Licensed User
Longtime User
it is indeed a strange coincidence! any idea how or why that's happening, because i like it!

that code above will surely have the exported message after every file is uploaded? i was trying to have it appear just once at the end.
 
Upvote 0
Top