Assign a non-null adapter adapter to a SuperRecyclerView instance recyclerView: recyclerView.setAdapter(adapter)
Assign a null adapter to the recyclerView: recyclerView.setAdapter(null).
Call adapter.notifyDataSetChanged().
The recyclerView will get notified since the observer is not cancelled. But now, recyclerView.getAdapter() will return null, this will crash when recyclerView.getAdapter().getCount() is called.
This PR fixed this issue by cancelling the observation once the adapter is changed. (Essentially this is how the official RecyclerView handles adapter changing.)
How to reproduce the bug:
adapter
to a SuperRecyclerView instancerecyclerView
:recyclerView.setAdapter(adapter)
recyclerView
:recyclerView.setAdapter(null)
.adapter.notifyDataSetChanged()
.The
recyclerView
will get notified since the observer is not cancelled. But now,recyclerView.getAdapter()
will returnnull
, this will crash whenrecyclerView.getAdapter().getCount()
is called.This PR fixed this issue by cancelling the observation once the adapter is changed. (Essentially this is how the official RecyclerView handles adapter changing.)