android.os.TransactionTooLargeException when using giant recycleview - android

I'm getting this annoying exception in my main activity sometimes.
the stack trace is like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tomatedigital.lottogram, PID: 4430
java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 543588 bytes
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4156)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.os.TransactionTooLargeException: data parcel size 543588 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:761)
at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:5147)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4148)
at android.os.Handler.handleCallback(Handler.java:789) 
at android.os.Handler.dispatchMessage(Handler.java:98) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6944) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
The trace itself is not very helpfull since it doesn't specify which component or what transaction Id or Tag is related to the Exception (google please think about the debuggability of the crap you put out there)...
but i do suspect it is the recycleview i have in my main activity.
This recycleview might get super loaded, THOUSANDS of items. each of them contains: 3 small strings, 1 large string and one small bitmap.
When this recyclerview is overloaded and the activity is suspended this exception is thrown. Since the recyclerview is created inflating the layout.xml, android do save its state automaticly.
Is there any easy way to workaround this problem?
Is possible to set the App to allow "super large Transaction"?
What can i do?
================UPDATE===================
to provide aditional information about my Activity
#Override
protected void onSaveInstanceState(#NonNull Bundle outState) {
outState.putSerializable("media", this.media); //this is a domain class
outState.putBoolean("canceled", this.canceled);
outState.putInt("speed", this.speed);
outState.putLong("startTime", this.startTime);
outState.putSerializable("comments", (Serializable) this.adapter.getList()); //this is the large data
outState.putBoolean("commentLoadComplet", this.complete);
outState.putSerializable("fetched", (Serializable) this.fetched);
outState.putSerializable("igiboAttendees", (Serializable) this.igiboAttendees);
outState.putLong("winnerId", this.winnerId);
super.onSaveInstanceState(outState);
}

This is typically caused by saving large amounts of data in onSaveInstanceState, not only for the activity in which the exception occurred, but also in other activities currently in the back stack.
One solution is to use the ViewModel class to maintain state instead of onSaveInstanceState:
ViewModel Overview
You may still use onSaveInstanceState for small amounts of data, but keep in mind it adds up over all the activities.

Related

No view found for id ### when loading fragments with dynamic framelayout

i have created a fragment to road some data but i want to load this fragment in n-number of containers which i want make this a dynamic like let say i have to load 10 fragments like this then in loop am creating a 10 number of frame layout and loading the fragment in it.
This is working fine but it is failing in the scenario where i moved to another come back to this fragment by pressing device back, there it is crashing and showing the below exception
java.lang.IllegalArgumentException: No view found for id 0x7f0b0c1e (:id/fragmentMy for fragment MyFragment{10b5860} (d681f0eb-720b-40e2-8240-9b45310a13b5 id=0x7f0b0c1e tag=My fragment 0)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:513)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:261)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1840)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1758)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1701)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:488)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
does any one any idea how to fix this, BDW am using child fragment fragment while loading this fragments inside a fragment
i have loading the same stuff with static xml layout also but still facing the same exception
even i removing all the view inside a layout before loading new frames layouts

FirestorePagingAdapter crashes when scrolling in version 8.0.1

After updating FirebaseUi from implementation 'com.firebaseui:firebase-ui-firestore:8.0.0' to implementation 'com.firebaseui:firebase-ui-firestore:8.0.1' FirestorePagingAdapter crashes when I scroll the RecyclerView. I think it always crashes at the same position, maybe at this position it loads new items for the first time.
I get the following crashlog:
java.lang.IllegalStateException: The same value, PageKey{StartAfter=1MbZLsOSoWUPAdDnNOGlthxGjDC2 - 02:52:33 - 11.04.2022, EndBefore=null}, was passed as the nextKey in two
sequential Pages loaded from a PagingSource. Re-using load keys in
PagingSource is often an error, and must be explicitly enabled by
overriding PagingSource.keyReuseSupported.
at androidx.paging.PageFetcherSnapshot.doLoad(PageFetcherSnapshot.kt:419)
at androidx.paging.PageFetcherSnapshot.access$doLoad(PageFetcherSnapshot.kt:54)
at androidx.paging.PageFetcherSnapshot$doLoad$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:233)
at android.app.ActivityThread.main(ActivityThread.java:8063)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

Vector animation in RecyclerView

Preface
I want to implement a download animation in RecyclerView. In onBindViewHolder and onViewRecycled I subscribe to and unsubscribe from presenter which retrieves the percentage of already downloaded file.
I start animation:
AnimatedVectorDrawableCompat drawable = AnimatedVectorDrawableCompat.create(context, R.drawable.download_animated);
if (drawable != null) {
holder.downloadingIcon.setImageDrawable(drawable);
drawable.start();
}
Problem
I have got onViewRecycled invoked right after the animation is finished with follow stacktrace:
java.lang.RuntimeException
at EventRecyclerViewAdapter.onViewRecycled(EventRecyclerViewAdapter.java:271)
at android.support.v7.widget.RecyclerView$Recycler.dispatchViewRecycled(RecyclerView.java:6064)
at android.support.v7.widget.RecyclerView$Recycler.addViewHolderToRecycledViewPool(RecyclerView.java:5835)
at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5800)
at android.support.v7.widget.RecyclerView.removeAnimatingView(RecyclerView.java:1305)
at android.support.v7.widget.RecyclerView$ItemAnimatorRestoreListener.onAnimationFinished(RecyclerView.java:11775)
at android.support.v7.widget.RecyclerView$ItemAnimator.dispatchAnimationFinished(RecyclerView.java:12275)
at android.support.v7.widget.SimpleItemAnimator.dispatchChangeFinished(SimpleItemAnimator.java:304)
at android.support.v7.widget.DefaultItemAnimator$7.onAnimationEnd(DefaultItemAnimator.java:363)
at android.support.v4.view.ViewPropertyAnimatorCompatJB$1.onAnimationEnd(ViewPropertyAnimatorCompatJB.java:51)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1121)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1149)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1309)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at android.animation.AnimationHandler.-wrap2(AnimationHandler.java)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:957)
at android.view.Choreographer.doCallbacks(Choreographer.java:734)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:945)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Question
Why it behaves like so and how can I fix it?
It turns out, notifyItemChanged caused to recycler previous ViewHolder so onBindViewHolder and onViewRecycled are invoked... but on different instances. Firstly onBindViewHolder is invoked with new ViewHolder instance. Next onViewRecycled is invoked with the old ViewHolder. In my case problem was relying only on one id of the model. It doesn't unambiguously describe Presenter's View I used to notify about updates.

transfer searchview from actionbar to layout

hey guys i want to transfer my searchview from actionbar to inside of my android layout but when im transfering it ill get crashed. how to fix this problem? thanks for any help.
here is my logcat
04-12 19:57:28.277 25122-25122/com.example.lightning.myapplication3 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.lightning.myapplication3, PID: 25122
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.lightning.myapplication3/com.example.lightning.myapplication3.SetRouteActivity}: java.lang.ClassCastException: android.widget.SearchView cannot be cast to android.support.v7.widget.SearchView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2584)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2650)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
Caused by: java.lang.ClassCastException: android.widget.SearchView cannot be cast to android.support.v7.widget.SearchView
at com.example.lightning.myapplication3.SetRouteActivity.onCreate(SetRouteActivity.java:53)
at android.app.Activity.performCreate(Activity.java:6270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2537)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2650) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5776) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) 
What you receive is a ClassCastException
This means, the type you use is wrong.
searchView = (SearchView)findViewById(R.id.pointa);
You have two choices:
1) Look for the import statement of SearchView at the top of this class file and change it from android.widget.SearchView to android.support.v7.widget.SearchView (or the other way round).
2) Take a close look at your XML file, looking for the <SearchView Tag. Is it possible, that because of the move, it changes from widget to support SearchView?
One of those two will fix your problem.
Hope this helps.

Android Weird Null Object Reference on Button.setText(mText)

I'm stuck with the weirdest error I've ever got since I started programming. I'm setting a text to a button. Nothing complicated there!
I do it this way:
btnButton.setText(cell.getText());
btnButton exists since I've passed some others things to it before setting its text and cell.getText() is not null either since I can log the text in my console.
Still, I get this weird error:
03-31 14:58:35.407 24398-24398/ca.gggolf.agggolf.full E/AndroidRuntime: FATAL EXCEPTION: main
Process: ca.gggolf.agggolf.full, PID: 24398
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at android.widget.TextView.checkForRelayout(TextView.java:6836)
at android.widget.TextView.setText(TextView.java:4063)
at android.widget.TextView.setText(TextView.java:3921)
at android.widget.TextView.setText(TextView.java:3896)
at ca.gggolf.agggolf.activities.fragments.AutoGridFragment.displayAutoGridBody(AutoGridFragment.java:467)
at ca.gggolf.agggolf.activities.fragments.AutoGridFragment.createAutogridBody(AutoGridFragment.java:206)
at ca.gggolf.agggolf.activities.fragments.AutoGridFragment.onCreate(AutoGridFragment.java:94)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1939)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Can someone help me fix this? It sometimes work but it depends from where in the application that I come from.
Thanks!
EDIT
Here's my whole code when creating the button. I assign it's width and initial text and then if the text should be truncated, I measure to make sure that my button will still fit in the size I gave it otherwise, I change it to textView.
It's when I set it back to normal after that it gives me the error.
Button btnButton = new Button(getActivity());
btnButton.setWidth(width);
btnButton.setText(cell.getText());
if(adjustedAutogrid.getColumn(indexCell).isTruncated()){
btnButton.setText("…");
btnButton.measure(0, 0);
if(btnButton.getMeasuredWidth() > width){
TextView btnText = new TextView(getActivity());
btnText.setWidth(width);
btnText.setText(cell.getText());
cell.getCSS().applyToTextView(btnText);
btnText.setEllipsize(TextUtils.TruncateAt.END);
btnText.setLines(1);
layout.addView(btnText);
break;
}
btnButton.setText(cell.getText());
btnButton.setEllipsize(TextUtils.TruncateAt.END);
btnButton.setLines(1);
}
And for those wondering from where it causes problem, well it's a bit complicated. I receive information through internet (an XML) that I convert to a table that I show. I must set the different cells the appropriate size and content. When I load what we call an AutoGrid coming from the XML, all my AutoGrid works except for one...
Edit 2
Everything works fine if I leave the text to the ellipsize symbol (…). It really is when i try to set the text again that it doesn't work..
I don't know why but it seems that if I set the text later with my button that everything is fine...
btnButton.setWidth(width);
btnButton.setEllipsize(TextUtils.TruncateAt.END);
btnButton.setLines(1);
btnButton.setText(cell.getText()); // this line used to be the first one
If someone has an explanation, please fill free to enlighten me!

Categories

Resources