Android Question Sleep(0) does not replace DoEvents

adriano.freitas

Active Member
Hi!

I have a Sub that processes Google Contacts data from an account that has thousands of records, so the loop that does the processing causes the app to "hang", generating an Android warning. If the user waits, everything works, however, the Android warning and not being able to insert an animated GIF to indicate processing, for example, make the user think there is a problem. So I created a panel that overlays the Application Screen with an animated progress gif. But even if I insert the code so that it is visible, it doesn't work because soon the loop starts and the screen doesn't get updated. My intention would be to put something like DoEvents in the middle of the loop to allow the animated gif to be displayed and move and so that the android system doesn't issue warning as if the app crashes. With DoEvents everything works perfectly, however, if I try to use Sleep(0) I need to change the sub to resumedsub. The problem is that the app is quite complex and has sub calling sub, calling sub, etc. This makes me have to change a lot of things in the code. Even so, I decided to change, however, there are several errors in the code because of unforeseen situations for the change. I solve one problem and cause several others. So I returned with DoEvents and everything worked again. I wanted to know what I can do to remove the DoEvents but not lose functionality, causing the loop not to crash the program and allow the screen to be refreshed. Any idea?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Adding Sleep is a possible solution, but it does affect the program flow.
Other options:
1. Use ContentResolver.QueryAsync to retrieve the data asynchronously.
2. Don't get the whole data at once. Specifically don't try to get the full contacts data.
3. Split the work. Add more contacts as the user scrolls the list (I'm guessing here...)
 
Upvote 0
Top