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

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

Related

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)

android.os.TransactionTooLargeException when using giant recycleview

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.

Error in navigation after creating new Realm object

I'm using the react-native-navigation package as well as Realm in my project. My app has a realm object called Notebook that contains a list of Verse objects, which are another realm object.
The structure of the app is very simple, the first page shows a list of Notebooks and when one is selected, the app transitions to the second screen which is a list of Verses.
Here is my code to navigate from the notebook list to the verse list:
this.props.navigator.push({
screen: 'com.beyersapps.biblebinderrn.verselist',
title: notebook.name,
passProps: {notebook: notebook},
animated: true,
animationType: 'fade',
backButtonTitle: undefined,
backButtonHidden: false
})
This navigation works fine and I can move back and forth between the two screens. My problem comes when I create a new Verse and add it to the Notebook. Here is my code that lives in the second screen to create a new Verse:
realm.write(() => {
let newVerse = realm.create('Verse', {
reference: 'Genesis 1:1',
favorite: false,
memorized: false,
scripture: 'My favorite verse'
});
if (this.notebook != null) {
this.notebook.verses.push(newVerse);
}
});
This is where my problem starts. At this point, if I select the back button to go back to the list of Notebooks, then select a notebook again, I get this error:
Attempting to change value of a readonly property.
Exception in native call
java.lang.RuntimeException: Error calling RCTEventEmitter.receiveTouches
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:154)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:199)
at java.lang.Thread.run(Thread.java:761)
Caused by: com.facebook.jni.CppException: Exception calling object as function: TypeError: Attempting to change value of a readonly property.
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
at android.os.Handler.handleCallback(Handler.java:751) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) 
at android.os.Looper.loop(Looper.java:154) 
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:199) 
at java.lang.Thread.run(Thread.java:761) 
There are a couple of things I can do to make this problem go away, but both make my app useless. Since they might help in determining the issue though I can either remove {notebook: notebook} from passProps when I navigate to the new screen (but then nothing shows on the Verse list screen since it does not know which Notebook was selected). Or, I can not add the newly created Verse to the selected Notebook (but then I can't add data).
Since these two changes are in two different components (Realm and react-native-navigation), I'm not sure which component is the source of the problem.
Objects passed as props (passProps) are frozen by React Native.
Try changing:
passProps: {notebook: notebook}
to:
passProps: {notebook: _.cloneDeep(notebook)}
If you need to reflect changes to the notebook in the previous screen, I think you should do so through the store.
Another option is to pass notebookId and get the correct notebook by id from state.

Android RecyclerView Endless Scroll adding item throwing Exception For Android Support Library 24.2.1

I have implemented the Endless scroll with RecyclerView. When user hit the bottom I'm adding null object to display progress in AsyncTask onPreExecute and notify adapter item Inserted. This code I have been using for quiet some time already. Recently I have updated android Support Library From 23.0.3 to 24.2.1. Since then I am getting exception when hit bottom of the list.
Cannot call this method in a scroll callback. Scroll callbacks might be run during a measure & layout pass where you cannot change the RecyclerView data. Any method call that might change the structure of the RecyclerView or the adapter contents should be postponed to the next frame.
java.lang.IllegalStateException:
at android.support.v7.widget.RecyclerView.assertNotInLayoutOrScroll(RecyclerView.java:2403)
at android.support.v7.widget.RecyclerView$RecyclerViewDataObserver.onItemRangeInserted(RecyclerView.java:4634)
at android.support.v7.widget.RecyclerView$AdapterDataObservable.notifyItemRangeInserted(RecyclerView.java:10472)
at android.support.v7.widget.RecyclerView$Adapter.notifyItemInserted(RecyclerView.java:6214)
at com.test.film.buzz.BuzzFeedsFragment$5.onPreExecute(BuzzFeedsFragment.java:229)
at com.test.utils.ParallelAsyncTask.executeOnExecutor(ParallelAsyncTask.java:595)
at com.test.utils.ParallelAsyncTask.execute(ParallelAsyncTask.java:543)
at com.test.film.buzz.BuzzFeedsFragment.onLoadMore(BuzzFeedsFragment.java:258)
at com.test.film.buzz.BuzzFeedsFragment$3.onScrolled(BuzzFeedsFragment.java:177)
at android.support.v7.widget.RecyclerView.dispatchOnScrolled(RecyclerView.java:4305)
at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4463)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
at android.view.Choreographer.doCallbacks(Choreographer.java:683)
at android.view.Choreographer.doFrame(Choreographer.java:616)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
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:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

Crash in Activity Transitions with SharedElement

I'm using Activity transitions from a ViewPager (in the calling activity) with a shared element and content transitions as well. I'm getting this crash when re-entering to the calling activity:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.os.ResultReceiver.send(int, android.os.Bundle)' on a null object reference
at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:199)
at android.app.EnterTransitionCoordinator.viewsReady(EnterTransitionCoordinator.java:123)
at android.app.EnterTransitionCoordinator$2.onPreDraw(EnterTransitionCoordinator.java:148)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:895)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2153)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1180)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6558)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
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:1399)
Also, Once going back, the screen begins to flicker continuously with a white screen flashing in and out.
Here are my Transition flags:
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowAllowReturnTransitionOverlap">false</item>
I tried setting Enter/Exit transitions both on the Calling and Called activity but no luck.
Try to get fragment from FragmentManager:
fragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + position)
If fragment is null, try creating a new fragment.
Activity transitions with shared elements can sometimes result in crashes due to various reasons. Here are a few common causes of crashes and how to avoid them:
Timing issues: Make sure that the shared elements have been properly sized and laid out before the transition begins. Delaying the transition start until after the shared elements have been fully initialized can prevent crashes.
Inconsistent names: If you are using shared element transitions between activities, make sure that the names of the shared elements in both activities are the same. Mismatched names can result in a crash.
Improper use of View.setTransitionName(): When using shared element transitions, it's important to set a unique transition name for each shared element. If two shared elements have the same transition name, a crash can occur.
OutOfMemoryErrors: Large images or Bitmaps used as shared elements can cause OutOfMemoryErrors, resulting in a crash. To avoid this, make sure to resize the images or Bitmaps to a smaller size before using them as shared elements.
Missing transition in XML: If the transition between the two activities is not defined in the XML, a crash can occur. Make sure that the transition is properly defined in the XML and that the correct transition is being used for the shared elements.
Here's an best example of avoid timing issues when using shared elements:
private void startActivityWithSharedElement(Intent intent) {
final ImageView sharedImageView = findViewById(R.id.shared_image_view);
sharedImageView.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
sharedImageView.getViewTreeObserver().removeOnPreDrawListener(this);
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(
MainActivity.this, sharedImageView, "shared_image").toBundle());
return true;
}
});
}

Categories

Resources