Android Question App crashes on key back event

Discussion in 'Android Questions' started by ivavilagu, Jan 25, 2015.

  1. ivavilagu

    ivavilagu Member Licensed User

    The app crashes when the key back button is pressed on a certain screen. Curiosly, it only crashes in real devices like a phone or a tablet, in the emulator works well.

    Code:
    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
        If KeyCode = KeyCodes.KEYCODE_BACK Then
            
    If (intNUM_PANTALLA = 1Then
                pantalla_principal
                
    Return True
            
    Else If (intNUM_PANTALLA = 2Then
                pantalla_referencia
                
    Return True             'Here is where the app crashes
            Else If (intNUM_PANTALLA = 3Then
                pantalla_principal
                
    Return True
            
    End If
        
    End If
    End Sub
    I'm searching the reason and the problem is because of a table class view added in 'pantalla_referencia' sub.
    Code:
    Sub pantalla_referencia
    .
    .
    .

    tbREFERENCIADB.Initialize(Me, 
    "tbREFERENCIADB"3)
    tbREFERENCIADB.AddToActivity(pnlREFERENCIADB, 
    00, pnlREFERENCIADB.Width, pnlREFERENCIADB.Height - 20%y)
    tbREFERENCIADB.SetHeader(
    Array As String("Referencia""Máquina""Puesto trabajo")) 
    tbREFERENCIADB.SetColumnsWidths(
    Array As Int(35%x20%x35%x))
    tbREFERENCIADB.FontSize = 
    16 * TextSizeRatio
    .
    .
    .
    end sub
    If I delete these lines the keyback function works fine. The log windows doesn´t show any error. In others parts of the app I call this sub and executes fine without problems, only crashes in the 'return true' line from key back. If I make a breakpoint in the 'return true' line I see in the screen device that the table has been created.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try to use CallSubDelayed to call these subs.
     
  3. ivavilagu

    ivavilagu Member Licensed User

    Thanks Erel, It works!!!!
     
  4. gz7tnn

    gz7tnn Member Licensed User

    I have a similar problem with the back button.
    I am using the following code and the result of pushing the back button differ on a 2.3.3 device and a KitKat one.
    The earlier device works fine and I can go thru the cycle of hitting the back button and responding "no" many times without it killing the app.
    Yet on the KitKat phone it will kill it. That is not always immediate, sometimes allowing 2 or 3 goes at doing it, but it eventually fails. Once it fails, after restarting the app it results in an immediate fail when trying the 'no' option again.
    My app has an activity and a service which handles sms messages, but the same apk on each phone behaves differently.
    Any clues? I am using activity.finish to allow the service to keep running.

    Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    Log("keypress")
    If KeyCode = KeyCodes.KEYCODE_BACK Then
    If Msgbox2("Are you sure to exit?", "", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
    'Log("Yes")
    Return False
    'ExitApplication '...or whatever other previous killing actions.
    Activity.Finish
    Else
    'Log("No")
    Return True
    End If
    End If

    End Sub

    Edit:
    I have created a new app with no more than a label and a button and get the exact same results. KitKat fails when responding "no" to the back button.
     
    Last edited: Apr 2, 2015
  5. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload this app? Which version of B4A are you using?
     
  6. gz7tnn

    gz7tnn Member Licensed User

    Hi Erel
    I am using B4A version V2.71
    The phone is on 4.4.4
     

    Attached Files:

  7. Erel

    Erel Administrator Staff Member Licensed User

    It will not happen with the latest version of B4A. I highly recommend you to update to a newer version. If you like, contact support@basic4ppc.com and we will send you a discount offer.
     
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