iOS Question ActivityIndicator Use

RichardN

Active Member
Licensed User
How is this View intended to be used?
B4X:
Private ActivityIndicator1 As ActivityIndicator       'Exists in loaded layout
Private i as int

'ActivityIndicator1.Visible = False        'Using this method is suggested elsewhere
ActivityIndicator1.Visible = True

For i = 0 to 1e6                'Loop many times
Next

ActivityIndicator1.Visible = False
This code does not work, the AI does not appear at all. Is there an iOS equivalent of DoEvents ???
 

RichardN

Active Member
Licensed User
The code within the loop looks something like this:

B4X:
Sub btnSearch_Click                 

    'Conducts Db wildcard search and sends results as HTML string to 'SearchResults' module
 
    ActivityIndicator1.Visible = True        'Defn exists in layout and Process_Globals
 
    Private Events As ResultSet
    Private EventCount As Int
    Private Clue as String = txtClue.Text
    Private Query As String
    Private SearchResult As String
    Private sb As StringBuilder
 
    Query = "SELECT Event, FromYr, ToYr FROM Events WHERE Event LIKE ? ORDER BY FromYear"
    Events = Main.SQL1.ExecQuery2(Query,Array As String("%" & Clue & "%"))
 
    sb.Initialize
    sb.Append("<b><font size='5'>Word Search For  '" & Clue & "'</font></b><br><br>")
 
    Do While Events.NextRow
 
        Dim Event As String = Events.GetInt("FromYr") & " - " Events.GetInt("ToYr") & ": " & Events.GetString("Event")
        EventCount = EventCount +1
        sb.Append(Event  & "<br><br><hr size=2>")
             
    Loop
 
    If EventCount = 0 Then sb.Append("Clue returned no results")
 
    SearchResult = "<html><body>" & sb.ToString & "</body></html>"
    ActivityIndicator1.Visible = False
 
    SearchResults.Show ("Word Search",SearchResult)     'Module to display the HTML string in  a WebView
 
End Sub
It does seem rather bizarre that the default backcolour for the AI is transparent.... however, getting past that little programmer's trap....

The database has about 2000 rows and whilst it searches quickly enough on newer devices the search can take 10-15 seconds on an iPhone 4 where the user is faced with a frozen screen for the duration with no AI.

If I fix a query so as to contrive a longer search period, even on newer devices the AI still does not appear ???
 

RichardN

Active Member
Licensed User
<<Are you testing the performance in Release mode?>> Yes.

I have taken other measures to slicken up the code that seem to produce better results:

- Defining the SQL object locally rather than globally then destroying it at the earliest opportunity.
- Reducing ResultSet.Getxxxx("xxx") calls by using local vars with one call only for each Db field
- Increasing the required length of the wild-card '%clue%' to return fewer results

The pause in execution on the slowest test device (iPhone 4) is now acceptable for deployment without an ActivityIndicator for the user to look at.

.....The lack of ActivityIndicator remains an unsolved mystery!
 

Erel

Administrator
Staff member
Licensed User
Defining the SQL object locally rather than globally then destroying it at the earliest opportunity
I don't think that it has any real impact on the performance.

.....The lack of ActivityIndicator remains an unsolved mystery!
It is not really a mystery. The UI cannot be updated when the main thread is busy.
 
Top