Android Question Freeze on real device only

epiCode

Active Member
Licensed User
I have this strange problem where the program freezes on a touch event while executing simple setlayoutanimated animations:
however after trying to debug this is what I have observed
1. It happens only on real devices and not on emulator (emulator android version 7.1)
2. Program passes over the same code multiple times but does not freeze first few times.
4. Does not hang in debug mode
3. There is no error or crash. It just causes the running application to go into "App is not responding - close - wait".

I tried putting multiple log statements to check where exactly does the code stop responding, and found that it pauses on the beginning of a "If then" statement which is as simple as if moveright then (moveright is boolean variable)

I would appreciate if experts here can guide me on how else can it be debugged or what else can be done to find out the cause of freezing.
 

DonManfred

Expert
Licensed User
Longtime User
Upload a small project showing the problem. Noone can help without seeing the code
 
Upvote 0

epiCode

Active Member
Licensed User
Upload a small project showing the problem. Noone can help without seeing the code
B4X:
private Sub animateswipe(fromFrame As Int, toFrame As Int)
    If toFrame < fromFrame Then
        Dim moveright As Boolean = False
    Else
        Dim moveright As Boolean = True
    End If
    Dim outframe As Panel     = setpanel(toFrame)
    Dim inframe As Panel     = setpanel(fromFrame)
    outframe.Visible        = True
    inframe.Visible            = True

    If  moveright Then    ' <- this is the line at which freeze occurs
            inframe.SetLayout(-(100%x) ,inframe.Top,inframe.Width,inframe.Height)
            outframe.SetLayoutAnimated(500,100%x,outframe.Top,outframe.Width,outframe.Height)
            inframe.SetLayoutAnimated(500, 0,inframe.Top,inframe.Width,inframe.Height)
        Else
            inframe.SetLayout(100%x ,inframe.Top,inframe.Width,inframe.Height)
            outframe.SetLayoutAnimated(500,100%x,outframe.Top,outframe.Width,outframe.Height)
            inframe.SetLayoutAnimated(500, 0,inframe.Top,inframe.Width,inframe.Height)
            outframe.SetVisibleAnimated(500,False)                                   
        End If   
End Sub
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I believe that SetLayoutAnimated does not wait for the animation to complete before returning control back to the app.
I believe that you will have to put some sleeps in the code after each animation to allow the animation to complete before performing the next one.

for example the following code move the panel off the screen and then hides and removes its contents
B4X:
private Sub CloseOverlay As ResumableSub
    pnlOverlay.GetView(0).SetLayoutAnimated(200,0,pnlOverlay.Height,pnlOverlay.Width,pnlmenuoverlay.Height)
    Sleep(200)
    pnlOverlay.Visible = False
    pnlOverlay.RemoveAllViews
    Return Null
End Sub

Also remember that the position are relative to the views parent not to the screen, so using 100%x may not be appropriate.
 
Upvote 0
Top