Android Question Wait For

walterf25

Expert
Licensed User
Longtime User
Hi All, i need some clarification on how this method should work, i'm working on an app that retrieves emails and displays them on a listview, I need to be able to update the UI as the emails are being retrieved and inserted into a Data Base, the information i'm inserting into the DB is not much, only the From email Address, Subject, time etc...

I was using the threading library but read a post from @Erel where he does not recommend using this library, so i updated my library so that i can use the Wait For method instead, this works great but i want to be able to display a progressdialog while the emails are being retrieved and the list View is being filled in, the problem is that i 'am not seeing the progressdialog at all, the emails are retrieved and the list view gets filled in but the app hangs while this process is happening, any advice, am I missing something?

Here is a piece of the code i 'am using, i'm using the Ultimate List View library and i'am using the latest version

Code: Copy
Sub FillMailBox(cursor As Cursor)
    Log("inside fillmailbox....")
    Sleep(0)
    ProgressDialogShow2("Retrieving Emails, please wait...", False)
    Sleep(0)
    dbcursor = Common.SQL1.ExecQuery("SELECT * FROM inbox WHERE emailAddress = " & "'"&Common.email&"'" & " AND mailIndex=1 ORDER BY UUID DESC")
    mailList.ClearContent
    mapItems.Clear
    For i = 0 To dbcursor.RowCount - 1
        Dim NewItem As typItemData
        NewItem.Initialize
        NewItem.Text = "item #: " & i
        NewItem.Anim.Initialize(Me, "Anim_AnimationEnd")
        Dim ID As Long = i
        mapItems.Put(ID, NewItem)
        mailList.AddItem("mail_retrieve", ID)
        mailList.SetSwipeDirection(i, mailList.SWIPE_DIRECTION_BOTH)
    Next
    mailList.AnimationCleaner = True
    ProgressDialogHide
End Sub

As you guys can see i'am calling the progressDialogShow2 method, but the dialog is not showing at all, i've tried without the Sleep(0) lines before and after calling the progressdialogshow2 method and it doesn't work either.

Thanks all for the help.

Walter
 
as it all happends in that sub it won't display since the screen will only update at the end of the sub.

try just the progressdialogshow and then use callsubdelayed to process the query and dialoghide.
 
Upvote 0
1. Use ExecQueryAsync instead of ExecQuery. It is very simple: [B4X] SQL with Wait For


2. Assuming that the loop takes a long time to complete then you can add:
Code: Copy
If i Mod 1000 = 0 Then Sleep(0)
Thanks Erel, isn't that the purpose of the Wait For method, doesn't this make it Asynchronous task?

Walter
 
Upvote 0
as it all happends in that sub it won't display since the screen will only update at the end of the sub.

try just the progressdialogshow and then use callsubdelayed to process the query and dialoghide.
Thanks Sorex, i'll give that a try.
 
Upvote 0
There is no reason to use CallSubDelayed. The call to Sleep(0) is the same.

Thanks Erel, isn't that the purpose of the Wait For method, doesn't this make it Asynchronous task?
No.
It will only be asynchronous if you use the async method.

BTW, you shouldn't build the query like this. Use parameterized queries. They are simpler.
 
Upvote 0
It will only be asynchronous if you use the async method.
Got it, that makes sense now, i can make all my functions in the java library Async Tasks.

BTW, you shouldn't build the query like this. Use parameterized queries. They are simpler.

I'am using parameterized queries, is only on this specific query i forgot to do that.

Thanks @Erel
Walter
 
Upvote 0
Upvote 0
You can use the Net library. The POP object handles the communication asynchronously.

Thanks Erel, the Chilkat email library i'm using is what my client suggested i use, it handles imap, pop, encryption and a lot more features.

Regards,
Walter
 
Upvote 0
Back
Top