Hey <@UJBPFB3SN>, what would be the solution to av...
# android
m
Hey @Ian Lake, what would be the solution to avoid this happening? https://issuetracker.google.com/issues/168779518 We have an app that creates fragments upon item selection in a RV and AFAIK, calling
popBackstackImmediate()
to go back invalidates the fragment and queues it for GC. We're calling
registerForActivityResult
in those fragments which eventually causes this overflow if the user stays in the app for long enough because our
registerForActivityResult
calls keep incrementing the counter.
i
If your user stays in the app long enough to create over 23 thousand fragments, I think you should be quite proud lol
But yeah, you've filed the bug in the right component, so we'll take a look
m
Thanks. The original reporter, Jason, hasn't received his invite to this workspace yet but asked me to paste this response on his behalf: "It's not a matter of creating thousands of Fragments at the same time. I agree that would be totally nuts. It's about creating this many Fragments over the lifetime of an activity. Let's say a new Fragment is created in an onClick handler, which is rigged up to some UI element of a car's touchscreen. And this Fragment calls Fragment::registerForActivityResult for 8 different things it cares about in its constructor. Now that means that after 8192 touches, the 2^16 requestCode counter will have overflowed and the app will crash. So, on a long road trip, touching the car's touch screen control 8192 times will crash the media console. Bad news bears!"
i
Yep, we'll fix it
m
Awesome
j
@Ian Lake whew, finally got in here! Thanks for looking into the registerForActivity result. It seems like it might be a serious issue and one that requires reconsidering just using an atomic integer for requestCode allocation. You'll probably need some kind of radix tree or free list system instead
i
Congrats on going through 23 thousand request codes! I wish I had a prize for you
j
@Ian Lake haha, do you mean 65k? or is the limit lower somehow?
i
The codes start at
0x10000
to avoid overlap with uses of the old API
j
Right, they start at 2**16
and then the check makes sure that none of the lower bits are set
so for a 32bit integer
it wraps around for the latter 16bits