0

A problem that is driving me mad for some time (and it's blocking publishing to Amazon app store, since the app had been suppressed but now I am stuck with this bug and they won't republish it...).

I have a layout with a list on the left and a grid on the right (shown in the screenshot). Clicking items of the list on the left (categories) calls an api, returns some stuff (movies) and displays them in the right section. Then when you click on a movie in the right fragment, something else should happen.

It has been working for some time, no user had complained, AND it DOES work on certain devices... for example it works on the amazon Fire version that runs android 7.1 but it doesn't work on their android 5.1 nor on the android 9 versions... [EDITED 16/12/2020: see the edit at the bottom of the question... by changing libraries - downgrading back to older versions - it now appears to only happen on the Android 9-based Fire devices, and the older ones - both 5 and 7 - do work]

On the problematic devices this is the strange behaviour that happens: if you select one of the first three items in the list, in the grid on the right my onClickListener don't fire. Starting from the 4th item onwards, the onClickListener fires and my code executes.

This is only happening when using a remote/dpad.... touch events work also on the first three... but the problem happens on certain models of Amazon Fire TV and other Android TV's that don't have touch and have to use the remote (on one emulator I can reproduce it, on the other one I can't... even if both are running android 10...)

The right piece is made with fragments - it's always the same fragment, always the same api call (just a different category as parameter to the api call), always the same type of stuff that returns and needs to be displayed, passing thru the same adapter, holder, etc etc...

I am lost as to where to look into. I even tried downgrading libraries, compiler, etc... I can share pieces of the code (altough I have to do a lot of cleanup and it would still be quite a bit because it's a complex layout with many pieces... but it's very similar to this set onClickListener in getview() with ViewHolder class . I also checked this https://scottweber.com/2013/04/30/adding-click-listeners-to-views-in-adapters/ and I get the exact same behaviour...) but if the code was really broken, it would NEVER work... but the fact that it 'generally works' but not for the first three items in the list baffles me... as I already wrote: this would be the same fragment, same code... very weird. That's why I suspect a platform/library/compiler issue.. ...but I am lost as to where to look at...

enter image description here

EDITED / UPDATED 16/12/2020: After I submitted a version where I downgraded a LOT of libraries AND gradle as well (and no code change on my end), then I was able to get it approved on the Amazon store again but with limited devices compatibility. Basically they say it works on the oldest devices and breaks only on (some of) the newer ones... interesting. I still havent' found the culprit, but at least there is a sort of direction as to where to look at...

  • It seems it's for Android TV but I guess Android app's strategy could work here as well. Are you using RecyclerView? And, have you tried setting up a click listener directly in your activity rather than in your adapter. I don't know if this is how it works in Android TV. But if yes, then you can give it a shot. – Basu Dec 08 '20 at 15:38
  • It's not a recyclerview - it's just a android.widget.GridView . It needs to display just 6 items on that screen size - or 16 at most. I understand that RecyclerView is the current, more modern, more memory-efficient, more-whatever way... but with this number of items it really sounded like overkill with no real performance benefit... this runs just fine on very old devices down to android 5... – Daniele Muscetta Dec 09 '20 at 20:03
  • The activity this is contained in is already a rather long piece of code and it contains a lot of conditional choices to change layout based on form factor (phone/tablet/tv). There are onclicklistener for the list on the left, which trigger removal and addition or replacement of fragments on the right. Then, in the fragments on the right (in the adapter they use), it's where the clicklisteners for those items are.... it would also be cumbersome to bind them from the activity to something that the activity doesn't really know much about or considers a black box: the fragments being replaced... – Daniele Muscetta Dec 09 '20 at 20:06
  • I did try to add a few fake items 'on top' of the list on the left and - lol and behold - the rest of it, once 'moved down' this way, it starts working. It's ridiculous, I have really no idea where to look at anymore... – Daniele Muscetta Dec 09 '20 at 20:08
  • and when they don't work, it's just with the REMOTE that it doesn't work..... because with touch (if available) the issue doesn't exist: it just works. Also with the remote on many devices it still works.... only on some it doesn't, but I can't isolate any specific difference to understand what is the actual, relevant, difference... – Daniele Muscetta Dec 09 '20 at 20:15

1 Answers1

0

It appears that if I set

android:descendantFocusability="afterDescendants"

on the GridView, then it works more reliably.

I am still doing more regression testing on old and new versions.... and I have no idea why the focus stealing happens only for some instances of that fragment and not for other ones...

Useful other threads I looked at and helped me in the right direction (and I had to buy a new Fire TV Stick of the new generation to be able to reproduce and debug it):