chucker icon indicating copy to clipboard operation
chucker copied to clipboard

WrongFragmentContainerViolation with TransactionOverviewFragment

Open wbervoets opened this issue 2 years ago • 5 comments

:writing_hand: Describe the bug

When clicking on a transaction Chucker crashes with the following exception:

Fatal Exception: androidx.fragment.app.strictmode.WrongFragmentContainerViolation Attempting to add fragment TransactionOverviewFragment{ff4002b} (ab14c612-b5e4-41c1-8a05-05a1816b3c62 id=0x7f0a037c) to container androidx.viewpager.widget.ViewPager{3b95f96 VFED..... ......I. 0,0-0,0 #7f0a037c app:id/viewPager} which is not a FragmentContainerView

I'm using AndroidX Fragment 1.4.1 and have enabled following strictmode checks:

FragmentStrictMode.defaultPolicy = FragmentStrictMode.Policy.Builder() .detectFragmentReuse() .detectFragmentTagUsage() .detectRetainInstanceUsage() .detectSetUserVisibleHint() .detectTargetFragmentUsage() .detectWrongFragmentContainer() .penaltyDeath() .build()

:bomb: Steps to reproduce

  1. Make sure your app is using AndroidX Fragment 1.4.1 + enabled FragmentStrictMode checks
  2. Click on Chucker notification
  3. Click on a transaction from the transaction list
  4. Crashes with WrongFragmentContainerViolation Attempting to add fragment TransactionOverviewFragment

:wrench: Expected behavior

Show the details of the transaction

:iphone: Tech info

  • Device: All devices
  • OS: Android 10
  • Chucker version: 4.0.0-SNAPSHOT

:page_facing_up: Additional context

Using app with Fragment 1.4.1

wbervoets avatar Feb 17 '22 14:02 wbervoets

Thanks for your report.

I saw this issue, but the problem there is that this fragment is part of ViewPager and we decided to stick with ViewPager, because ViewPager2 had some issues (see more in #159).

So, I guess, till we migrate to some newer version of ViewPager2 (I suppose lint/strict mode won't complain about same issue there), which, probably, won't be released by Google anytime soon if at all, we can't get away from this problem.

vbuberen avatar Feb 17 '22 17:02 vbuberen

Thanks for the clarification. For now I'll disable the WrongFragmentContainer check when I need the Chucker functionality.

Am I correct to assume that the issues you were experiencing with Viewpager2 are fixed in the 1.1.x series? (so we need to wait until ViewPager2 1.1.0 gets a final release)

wbervoets avatar Feb 18 '22 06:02 wbervoets

maybe we should ping @jfresen from Google @to see if a 1.1 release is coming in the near future ? :-)

wbervoets avatar Feb 18 '22 06:02 wbervoets

Am I correct to assume that the issues you were experiencing with Viewpager2 are fixed in the 1.1.x series?

Note, it is mostly a speculation from my side that ViewPager2 resolves the issue with Strict mode

As long as I remember we had only one of issues with options menu flickering resolved back then. However, I used alpha builds at that time. Maybe something changed with beta version. Among other issues we had were:

  1. Wrong options menu items, which I mentioned in the mentioned PR with migration.
  2. Some UX issue, which is described here: https://medium.com/@BladeCoder/fixing-recyclerview-nested-scrolling-in-opposite-direction-f587be5c1a04

Looking at dates of releases of ViewPager2 I doubt that we will see a stable release soon. It is already a few years passed since 1.0 release and 1.1 isn't a plan, probably, since focus might be shifted from such libraries to Jetpack Compose. So my expectation is that Chucker will migrate to Jetpack Compose faster than Google releases ViewPager2 😄

vbuberen avatar Feb 18 '22 07:02 vbuberen

Hi. Yes, our focus has shifted to Jetpack Compose indeed. If you are planning to migrate to Compose, that is probably the best option for you.

jfresen avatar Feb 23 '22 17:02 jfresen