This is quite a nasty bug.
To handle my item click, I used an implementation of the RecyclerView.OnItemTouchListener
similar to the solution found in this question.
After many times of refreshing the RecyclerView
's datasource and clicking an item, this IndexOutOfBoundsException
would crash my application. When an item is clicked, the RecyclerView
internally goes looking for the correct underlying view and gives back it position. Checking out the source code, I saw that there were some Tasks
and Threads
scheduled. To cut the story short, basically it's just some illegal state where two datasources are intermixed and not synchronized and the whole thing goes wild.
Based on this, I removed my implementation of the RecyclerView.OnItemTouchListener
and simply caught the click on the ViewHolder
of the Adapter
myself:
public void onBindViewHolder (final BaseContentView holder, final int position) {
holder.itemView.setOnClickListener(new OnClickListener() {
@Override
public void onClick (View view) {
// do whatever you like here
}
});
}
This might not be the best solution, but a crash-free on for now.. Hopefully this will save you some time :).