Android Question CustomListView - Transaction too large crash when going to pause.

alon

Active Member
Licensed User
Hi ,

I have a problem with my app in some devices.

the problem is that when my app going to pause, it crash with Transaction too large.


I saw a post from jmon ( https://www.b4x.com/android/forum/threads/solved-transaction-too-large-crash.100292/#content )
with the same problem saying that when we have a lot of items on the CustomListView, the app is crash.
and that is the same problem that I have.


I would like to know if there are other solutions for the problem?


p.s

His solutions was to clear the list before going to pause and refill it on resume,
or to use the standard listview.



Thanks
 

Erel

Administrator
Staff member
Licensed User
Can you post the full error message from the logs?

Are you able to reproduce it?

You can always switch to lazy loading and then the number of views will be much smaller.
 

alon

Active Member
Licensed User
Can you post the full error message from the logs?

Are you able to reproduce it?

You can always switch to lazy loading and then the number of views will be much smaller.

Hi,
I prefer not to use lazy loading.


Thanks


the error is:



** Activity (frmkibuy) Pause, UserClosed = false **
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 532604 bytes
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:160)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: android.os.TransactionTooLargeException: data parcel size 532604 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:1131)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:3973)
at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:144)
... 7 more
 

AnandGupta

Well-Known Member
Licensed User
Hi,
I prefer not to use lazy loading.
@alon, can you specify the reason ?

Actually as I read all over the forum, it is best to use lazy loading in clv if you have lots of data. So your reason may throw some light to it.

Regards,

Anand

Edit: Don was fast, as usual :), and may have given you the required solution, still if you may tell the reason.
 

alon

Active Member
Licensed User
Then DO NOT load such much data at once. You are going over the sqlite max transactionamount.
Fetch less data at once and it will work.
I dont understand why there is a problem with the sqllite.

the app is crashing after I have alreay build the listview from the sql.
and after that i am not reading again from the sql.

The app does not crash while reading from sql or while creating objects on the listview.
 

DonManfred

Expert
Licensed User
Found on stackoverflow

encountered this issue, and I found that when there huge amount of data getting exchanged between a service and an application,(This involves transferring lots of thumbnails). Actually data size was around 500kb, and the IPC transaction buffer size is set to 1024KB. I am not sure why it exceeded the transaction buffer.

This also can occur, when you pass lot of data through intent extras

When you get this exception in your application, please analyze your code.

  1. Are you exchanging lot of data between your services and application?
  2. Using intents to share huge data, (for example, the user selects huge number of files from gallery share press share, the URIs of the selected files will be transferred using intents)
  3. receiving bitmap files from service
  4. waiting for android to respond back with huge data (for example, getInstalledApplications() when the user installed lot of applications)
  5. using applyBatch() with lot of operations pending
How to handle when you get this exception

If possible, split the big operation in to small chunks, for example, instead of calling applyBatch() with 1000 operations, call it with 100 each.

Do not exchange huge data (>1MB) between services and application

I dont know how to do this, but, Do not query android, which can return huge data :)

As the TO do not provide any useful info it is hard to give any congrete advice.
 

alon

Active Member
Licensed User
@alon, can you specify the reason ?

Actually as I read all over the forum, it is best to use lazy loading in clv if you have lots of data. So your reason may throw some light to it.

Regards,

Anand

Edit: Don was fast, as usual :), and may have given you the required solution, still if you may tell the reason.
Hi,
The reason is that the listview contains fields that should be update the sql db,

and after the user fill in the relevant filed, he press on a "Save Button"
The save Button runs on all the fields in the listsview and update the sql db.

now as I understand (maybe I'm wrong)
if i will use lazy loading i need to update every record on the list view, immediately after the use make change to any of the fields.
 

DonManfred

Expert
Licensed User
if i will use lazy loading i need to update every record on the list view, immediately after the use make change to any of the fields.
if you are updating the values in the Sqlite DB one by one i would suggest to create smaller transactions. maybe 50-100 at once.
go over the list and put the updatesql in a batch until the batch has a size of 50 (or 100). Send the batch and wait for finish of the batch.
Fill another batch with the next 50/100 items. send the batch, wait for result.....

Until you updated all values.
 

AnandGupta

Well-Known Member
Licensed User
Hmm..Don's suggestion looks good if you do not want to do lazy loading, but updating sql after each user change, is background process (async) I think, and would not slow the view down.

Regards,

Anand
 

alon

Active Member
Licensed User
Thanks you all for trying to help.

I guess I will use Don's suggestion .
but before doing that I will try to check what Don's Found on stackoverflow.

the problem is that it can't be debugged buy the IDE.

anyhow thanks again.


and if you will have a new idea I will be happy to know.
 

alon

Active Member
Licensed User

Erel

Administrator
Staff member
Licensed User
You shouldn't use the old CustomListView. It was replaced by xCustomListView. It is very simple to switch between them. You just need to delete the old custom view and create a new xCLV.
 

alon

Active Member
Licensed User
You shouldn't use the old CustomListView. It was replaced by xCustomListView. It is very simple to switch between them. You just need to delete the old custom view and create a new xCLV.
I have already did that , and I have a few problems with CreateListItem

I have fixed the clv.Add method

and I am getting the following Error:



java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.res.ColorStateList.getDefaultColor()' on a null object reference
at anywheresoftware.b4a.objects.B4XViewWrapper.getColor(B4XViewWrapper.java:399)
at b4a.example3.customlistview._insertatimpl(customlistview.java:553)
at b4a.example3.customlistview._insertat(customlistview.java:535)
at b4a.example3.customlistview._add(customlistview.java:71)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at bina.YomanTech.yomanlist._drawlistview(yomanlist.java:801)
at bina.YomanTech.yomanlist._jobdone(yomanlist.java:1765)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:370)


I have added the sub and the line that call to the sub:

p.s. it is not that simple because i have a big project with a lot of activities using the same list view and I need to chane it all over and also to replace the object from the designer. :)

Thanks
B4X:
For i = 0 To Table.Size - 1 'Creating The Itmes Parents and childs
        Cols = Table.Get(i)
'        clvDoh.Add (CreateListItem($"Item #${i}"$, clvDoh.AsView.Width,  70dip) ,  $"Item #${i}"$) 
     
        clvDoh.Add(CreateListItem($"Item #${i}"$, clvDoh.AsView.Width, clvDoh.AsView.Height), $"Item #${i}"$)
   

    Next


Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    Dim su As StringUtils
    Dim stmp As String
    Dim item As ItemProp
    p.Initialize("")
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
'    Activity.AddView(p, 0, 0, Width, Height)
'    p.LoadLayout("listitem")

    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("listitem")



'    p.Background = Colors.Black
    p.RemoveView
 
    'label1 and button1 will point to the last added views.
    lblDetails.TextColor = Colors.Black
    lblTel.TextColor = Colors.Black
'    lblDetails.Color=Colors.Gray
'    lblTel.Color = Colors.Green
    Try 
        item.Initialize
        item.Recid = Cols(0)
        item.MisparTofes = Cols(1)
        item.Shlav = Cols(13)
     
     
        lblDetails.Tag = item    '
        stmp =  Cols(6) & CRLF    &  Cols(5)                 'sha + shemlako
     
        If ModFunc.Len(Cols(7)) > 0 Then 'ktovetlako
            stmp = stmp &  CRLF & Cols(7)     
        End If
     
        If ModFunc.Len(Cols(10)) > 0 Then 'teorparit
            stmp = stmp & CRLF & "תאור: " & Cols(10)
        End If
     
        If ModFunc.Len(Cols(11)) > 0 Then 'degem
            stmp = stmp & CRLF & "דגם: " & Cols(11)
        End If
        '===================================
        '26-11-2017
        If Starter.bShowTarikHatkana Then
            If ModFunc.Len(Cols(25)) > 0 And Cols(25) <> "01.01.1900" Then 'TarikHatkana
                stmp = stmp & CRLF & "תאריך התקנה: " & Cols(25)
            End If
        End If
        '===================================
        If ModFunc.Len(Cols(12)) > 0 Then 'takala
'            stmp = stmp & CRLF & "תקלה: " & Cols(12)
            stmp = stmp & CRLF & Starter.sTakalaName & Cols(12) '26-09-2019
        End If
     
        stmp = stmp & CRLF
        '==================================
        '21-01-2018
        cs =  ModFunc.MarkPattern(stmp, "\d\d\d\d\d\d\d\d\d+", 0)
        lblDetails.Text = cs
        cs.EnableClickEvents(lblDetails)
     
        '==================================
'21-01-2018        lblDetails.Text = stmp
        lblTel.Text = Cols(8)
        If Cols(34).Length > 0 Then '26-09-2019 Akrai
            lblTel.Text = Cols(8) & CRLF & Cols(34)
        End If
        '==================================
        '02-01-2018
        lblHatra.Visible = False
        If ModFunc.Val(Cols(18)) > 0 Then
            lblHatra.Text = "התראה " & Cols(18) & " דק'"
            lblHatra.Visible = True
        End If

        '==================================
        If stmp.Length > 0 Then
'21-01-2018            lblDetails.Text = stmp
            lblDetails.Height= su.MeasureMultilineTextHeight(lblDetails, lblDetails.Text)+ 2%y
            iItemHeight = lblDetails.Height
        End If
        '==================================
        '07-01-2018
        lblOved.Visible = False
        If Starter.bMenahelAvoda Then
            If ModFunc.Len(Cols(26)) > 2 Then
                lblOved.Text = "טכנאי: " &  Cols(26).SubString2(0,Cols(26).Length -2)
                lblOved.Visible = True
                lblOved.Top = lblDetails.Top + lblDetails.Height
                iItemHeight = iItemHeight + lblOved.Height
            Else
                If ModFunc.Len(Cols(15)) > 2 Then
                    lblOved.Text = "טכנאי: " &  Cols(15)
                    lblOved.Visible = True
                    lblOved.Top = lblDetails.Top + lblDetails.Height
                    iItemHeight = iItemHeight + lblOved.Height
                End If
            End If
        End If
        '==================================
        If ModFunc.Val(Cols(20)) = 1 Then 'status
            lblDetails.Color=Colors.ARGB(255,192,255,192)
            lblTel.Color=Colors.ARGB(255,192,255,192)
            p.Color=Colors.ARGB(255,192,255,192)
        End If
        '==================================
        '15-01-2018
        If Starter.bUserHag(0) Then
            Dim cTmpRec As Cursor
            Dim res(4) As Int
            cTmpRec = DBUtils.FnOpenRecSet(Starter.sql,"select * from StatusColors where TeorStatus = " & DBUtils.Fmsg(Cols(22)) )
            If cTmpRec.RowCount > 0 Then
                cTmpRec.Position = 0
                If ModFunc.Nul(cTmpRec.GetString("Zeva"), True).Length > 0 Then
                    res=ModFunc.getRGB(cTmpRec.GetString("Zeva"))
                    lblDetails.Color=Colors.RGB(res(0),res(1),res(2))
                    lblTel.Color=Colors.RGB(res(0),res(1),res(2))
                    p.Color=Colors.RGB(res(0),res(1),res(2))
                 
                End If

            End If
            If ModFunc.Val(Cols(20)) = 1 Then 'status
                res=ModFunc.getRGB(12640511)
                lblDetails.Color=Colors.RGB(res(0),res(1),res(2))
                lblTel.Color=Colors.RGB(res(0),res(1),res(2))
                p.Color=Colors.RGB(res(0),res(1),res(2))
            End If
        Else
            If Starter.bYeshKibuy Then '29-07-2019
                If DBUtils.FnQueryOK("select 1 from DohKibuyImg where sug = 271 And MisTofes = " &  item.MisparTofes & CRLF & _
                                " and Shlav = " & item.Shlav & " LIMIT 1 ") Then
                    p.Color=Colors.Green
                End If
            End If
        End If
        '==================================
        '23-09-2019
        If Starter.bYeshKibuy Then
            Dim imgSeker As ImageView
         
            If DBUtils.FnQueryOK("select 1 from DohKibuyImg where sug = 271 And MisTofes = " &  item.MisparTofes & CRLF & _
                                " and Shlav = " & item.Shlav & " LIMIT 1 ") Then
             
                imgSeker.Initialize("imgSeker")
                p.AddView(imgSeker,  5%x ,    lblDetails.Height / 2 ,     lblTel.Width ,    lblTel.Width)
                ModFunc.FitBitmapToImage(imgSeker,"seker.png","")
             
            End If
        End If
        '==================================
     
    Catch
        Log(LastException)
    End Try
 
    Return p
End Sub
 

Erel

Administrator
Staff member
Licensed User
I don't know whether it is related or not however this line should be removed:
p.RemoveView
 

alon

Active Member
Licensed User
I don't know whether it is related or not however this line should be removed:
p.RemoveView
I have tryied that already.


I also removed all my code from CreateListItem Sub and still the same problem
:

B4X:
For i = 0 To Table.Size - 1 'Creating The Itmes Parents and childs
        Cols = Table.Get(i)
        clvDoh.Add(CreateListItem( clvDoh.AsView.Width, clvDoh.AsView.Height), $"Item #${i}"$)
Next



Sub CreateListItem( Width As Int, Height As Int) As Panel
    Dim p As Panel
    Dim su As StringUtils
    Dim stmp As String 
    Dim item As ItemProp
    p.Initialize("")
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
'    Activity.AddView(p, 0, 0, Width, Height)
'    p.LoadLayout("listitem")

    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("listitem")



'    p.Background = Colors.Black
'    p.RemoveView

   
    Return p
End Sub
 
Top