Open St4B opened 6 years ago
What kind of list are you using? Depending on the implementation of the list you could get O(1) or O(n) random access time. I think LinkedList has O(n) whereas ArrayList has O(1).
I use ArrayList
@St4B my solution might not be the best, but I used something like this: http://blog.iamsuleiman.com/android-pagination-tutorial-getting-started-recyclerview/
I just load 20 or 30 elements at a time and you can set when you want the background system to fetch more. the logic on the backend becomes a bit more complex, because you have to pagenate your cursor, but it's not too bad especally with the use of RX. And this also helps with consuming a massive amount of memory at least initially.
If your project is relatively new without too much legacy code, your should consider using Android Architecture Components. In there you will find Room for handling database access and the pagination library for doing the load. These can seriously shave some complexity off the database handling. Take a look here: https://developer.android.com/topic/libraries/architecture/paging.html
I have an app that has a recyclerview. The recyclerview loads data using an custom adapter. If we set in our adapter a cursor with large data (For example 3000 rows) the recyclerview scrolls smoothly. If we set in our adapter a list of objects (even a small amount, like 500 objects) the recyclerview lags on scroll. I suppose that the reason is that we consume a lot of resources by this approach and also the cursor uses a window and not a reference to all the data.
My question is how to handle this situation? Before using clean architecture i just passed the cursor to the recyclerview and everything worked ok. After using rxJava I create an object in every onNext call and keep them in a list.
Also there is another problem. The domain layer does not have reference to android classes. As a result I can not have Observable in order to pass it to presentation layer. Is the best way to keep an unchecked observable? Is there any different approach (For example any rxJava operator)?