Android Question [Solved] System ask me if i want to stop the aplication

Discussion in 'Android Questions' started by RSL, Feb 15, 2015.

  1. RSL

    RSL Member Licensed User

    Hello everyone.
    I created a service module to perform a background update of many tables in my database.
    To notify the user that a process is running i'm using a CustomProgressDialog.
    No problem as it remains active during the process, but if the process is too long, the system shows the advice that my application is not responding, leaving me to wait or close.

    It's no problem the users close the aplication, as it is a service and the update will be finished, but no much clear for them.

    Is there a way to solve this? Maybe making the process in the activity or something?
     
  2. NJDude

    NJDude Expert Licensed User

    You will have to check your code, if the system is displaying that message is because it has become unresponsive, you might need to add a DoEvents or improve your code, hard to tell without seeing what you are doing.
     
  3. RSL

    RSL Member Licensed User

    So this is the code I call for each CSV file to update records
    Now I'm using 8 CSV over 700 records each file.

    Notes:
    - lsFic is a List previously loaded using StringUtils.LoadCSV2
    - fsUpdateQuery2 and fsInsertQuery are not posted. They are only to create query sentences.

    Code:
    Dim oSQL As SQL
    oSQL.Initialize(DBCREAR.DBFileDir, DBCREAR.DBFileName, 
    False)
    If oSQL.IsInitialized Then
        
    ' For every record in the file
        For i=0 To lsFic.Size-1
            
    Try
                
    ' Load fields into array
                Dim arr_ValReg(iNumCampTabla) As String
                arr_ValReg = lsFic.Get(i)
               
                
    ' Load key values
                Dim arr_ValClave(iNumCampClave) As String
                
    For j=0 To iNumCampClave-1
                    arr_ValClave(j) = arr_ValReg(j)
                
    Next
               
                
    ' Check if the record exists
                Dim c As Cursor
                c = oSQL.ExecQuery2(sQuery.ToString, arr_ValClave)

                
    If c.RowCount > 0 Then
                    
    ' Set the position
                    c.Position = 0

                    
    ' Capture ID
                    Dim iIdLinea As Int
                    iIdLinea = c.GetInt(
    "ID")

                    
    ' Generate field list for the update
                    Dim lsCampos As List
                    lsCampos.Initialize
                    
    For k=0 To mCamp.Size-1
                        lsCampos.Add(mCamp.GetKeyAt(k))
                    
    Next

                    
    ' Close cursor
                    c.Close
                   
                    
    ' Generate the update query
                    Dim sUpdate As String
                    sUpdate = fsUpdateQuery2(NomTabla,iIdLinea,lsCampos)

                    
    ' Update record
                    oSQL.ExecNonQuery2(sUpdate,arr_ValReg)

                    
    Log(NomTabla & " : record updated")
                
    Else
                    c.Close
                    
    ' Inser record
                    Dim sInsert As String
                    sInsert = fsInsertQuery(NomTabla,iNumCampTabla)

                    oSQL.ExecNonQuery2(sInsert,arr_ValReg)

                    
    Log(NomTabla & " : record insert")
                
    End If

            
    Catch
                
    Log(NomTabla & " : couldn't update")
            
    End Try
           
            
    DoEvents
        
    Next

        oSQL.Close
    End If
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Use transactions. It will make your code 1000 times faster.
     
    RSL likes this.
  5. RSL

    RSL Member Licensed User

    Thank's Erel. Now all works as it's suposed to be.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice