Android Question Problem with DoEvents on Android 4.4.2

Discussion in 'Android Questions' started by luciano deri, Jul 10, 2015.

  1. luciano deri

    luciano deri Active Member Licensed User

    I was made a simple App that accept on edit text and in edittext_enterpressed write a db and show a table designed with scrollwiev.
    Code:
    sub ET_EnterPressed
        
    if ET.Text = "" then
            
    return
        
    end if
        WriteDB
        ShowList
    end sub 'Crash in this point
    sub ShowList
        
    Dim PH As Int    : PH = 5%Y  
        ScrollView1.Panel.RemoveAllViews
      
        strquery = (
    "SELECT ..."'")
        dbCursor = Main.dbSql.ExecQuery(strquery)
        
    For i = 0 To dbCursor.RowCount - 1
            
    DoEvents
            dbCursor.position = i

            panel1.Initialize(
    "PRow")
            ScrollView1.Panel.AddView(ps, 
    0, i * PH, 100%x, PH)
            panel1.LoadLayout(
    "LayRow")

            ....
              
          
        
    Next
      
    ScrollView1.Panel.Height = dbCursor.RowCount * PH
        dbCursor.Close
    end sub
    This code is ok in android 4.1.2, but in 4.4.2
    is crashed without write anything on filtered log. Without filter i extract the position of log where the crash is done:
    DCD OFF

    Window spent 25225.9ms processing the last input event:

    Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 1685 (iscoapp.rilinve)

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    Build fingerprint: 'samsung/matisseltexx/matisselte:4.4.2/KOT49H/T535XXU1ANK1:user/release-keys'

    Revision: '3'

    pid: 1685, tid: 1685, name: iscoapp.rilinve >>> it.multidatanet.siscoapp.rilinve <<<

    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c

    r0 00000000 r1 bef38a80 r2 bef390f3 r3 00000040

    ....

    If comment DoEvent there isn't problems for every version. Why?
     
    Last edited: Jul 13, 2015
  2. MarcoRome

    MarcoRome Expert Licensed User

    What this ?
    Code:
    ScorllView1
     
  3. MarcoRome

    MarcoRome Expert Licensed User

    Try this :
    Code:
    For i = 0 To dbCursor.RowCount - 1
               dbCursor.position = i

            panel1.Initialize(
    "PRow")
            SVsinonimi.Panel.AddView(ps, 
    0, i * PH, 100%x, PH)
            panel1.LoadLayout(
    "LayRow")

            ....
              
             
    DoEvents 
        
    Next
     
  4. LucaMs

    LucaMs Expert Licensed User

    you are trying to add ps many times (in the loop).

    I suppose you want to add a new ps each time, then you should declare it inside the loop.

    If it should be Panel1... it's the same; Panel1 should be declared inside the loop.
     
  5. luciano deri

    luciano deri Active Member Licensed User

    The right metod is made a array of panel
    ScrollView1.Panel.AddView(ps(i), 0, i * PH, 100%x, PH)
    but the problem isen't here
     
    Last edited: Jul 13, 2015
  6. luciano deri

    luciano deri Active Member Licensed User

    The problem persist...
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    What is the purpose of the DoEvents call?
     
  8. luciano deri

    luciano deri Active Member Licensed User

    I think that DoEvents can help a slow device that showing the panels on cycle...
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    DoEvents should mostly be avoided.

    Use a timer instead if you want to show the panels while they are being added.
     
    Peter Simpson and KMatle like this.
  10. luciano deri

    luciano deri Active Member Licensed User

    Could give me an example? I use DoEvents every time i make long process of "for ... next" and i need show a ProgressDialogShow, without DoEvents the dialog not turn round...
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the code in the For / Next loop? How many rows are you adding there?

    Note that you can use CustomListView to handle the items.
     
  12. luciano deri

    luciano deri Active Member Licensed User

    Code:
    sub ShowList
        
    Dim PH As Int    : PH = 5%Y 
        ScrollView1.Panel.RemoveAllViews
     
        strquery = (
    "SELECT ..."'")
        dbCursor = Main.dbSql.ExecQuery(strquery)
        
    ProgressDialogShow("waith")
        
    For i = 0 To dbCursor.RowCount - 1
            
    DoEvents 
            dbCursor.position = i

            panel1.Initialize(
    "PRow")
            ScrollView1.Panel.AddView(ps, 
    0, i * PH, 100%x, PH)
            panel1.LoadLayout(
    "LayRow")

            ....
             
         
        
    Next
     
    ScrollView1.Panel.Height = dbCursor.RowCount * PH
        dbCursor.Close
    end sub
    This the original code, i dont know how many row has table.
    But with DoEvents only on samsung tab4 (Android 4.4.2) crash. Without is ok but with a lot of row the app appears blocked. So i thinked use ProgressDialogShow to wait, but only with DoEvents this turn round..
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. luciano deri

    luciano deri Active Member Licensed User

    Same Error, but without DoEvents
    Fatal signal 11 (SIGSEGV) at 0x0000000c (code=1), thread 1685 (iscoapp.rilinve)

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

    Build fingerprint: 'samsung/matisseltexx/matisselte:4.4.2/KOT49H/T535XXU1ANK1:user/release-keys'

    Revision: '3'

    pid: 1685, tid: 1685, name: iscoapp.rilinve >>> it.multidatanet.siscoapp.rilinve <<<

    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0000000c

    r0 00000000 r1 bef38a80 r2 bef390f3 r3 00000040
    ....
    Device Samsum TAB4, with older tablet i have no problem.
     
    Last edited: Jul 30, 2015
  15. Erel

    Erel Administrator Staff Member Licensed User

    Which code raises this error?
     
  16. luciano deri

    luciano deri Active Member Licensed User

    Code:
    Sub ETSinCod_EnterPressed
        btsalva_Click
    End Sub ' here crash
    Sub btsalva_Click
                 
    If ETSinCod.Text <> "" Then
                      LeggiSinonimo
                 
    End If
                 ETSinCod.RequestFocus
    End Sub
    Sub LeggiSinonimo
        EsisteSin = 
    True
        
    'verifica se il sinonimo è un codice articolo
        LeggiArticolo(ETSinCod.Text) 'make only a query to find  code in table
        If Not(NuovoArticolo) Then
          
    Msgbox("Codice sinonimo già utilizzato","Sinonimo non valido")  
          
    Return
        
    End If 
    End Sub
    I solved in this way, but this problem is becoming annoying, because the critical point is not where the program stops and the log does not say anything
    Code:
    Sub LeggiSinonimo
        EsisteSin = 
    True
            
    'verifica se il sinonimo è un codice articolo
        LeggiArticolo(ETSinCod.Text)
        
    If Not(NuovoArticolo) Then
          CallSubDelayed(
    "","messaggio")
          
    Return
        
    End If 
    End Sub
    Sub messaggio
        
    Msgbox("Codice sinonimo già utilizzato","Sinonimo non valido")  
    End Sub
     
    Last edited: Sep 14, 2015
  17. blong

    blong Member Licensed User

    I have also had problems with DoEvents in 4.4. Was fine on all earlier versions of Android I had tested. In 4.4 I simply removed all of the calls to DoEvents and had a less appealing user experience... BUT it worked.

    It just caused my application to exit at random times. Perhaps the CPU is so fast that it does items out of order. I agree that DoEvents is a dangerous thing to do but I concur with the reason you use it to give the USER some feedback that something is happening.
     
  18. Dave O

    Dave O Active Member Licensed User

    FYI, I've found that Android 6 devices (using the GenyMotion emulator at least, maybe for real too) seem to be more touchy about DoEvents than Android 4 or 5.

    Whenever I encounter a crash that seems inexplicable, I now include DoEvents in my "usual suspects" list of things to check. :)
     
Loading...