Skip to main content
Recyclerview View pool

Android Recyclerview View pool! what is that?

Where do the RecycledViews go ?

Most of us think that the RecyclerView picks recycled views from the ViewPool but that is not true, before consulting the ViewPool, there are multiple levels of caches that the RecyclerView goes through in the hunt for a ViewHolder, the Scrap, hidden views, ViewCache and the ViewCacheExtension.

The most prominent of those is the ViewCache, so let’s discuss when does a ViewHolder go into the ViewCache and when into the ViewPool. Once a ViewHolder gets recycled, it is pushed into the ViewCache which has a default size of 2, so it can hold as much as 2 views within it, after which it pushes the ViewHolders into the ViewPool, which acts like a Stack of ViewHolders.

So what’s the difference in keeping the ViewHolders in the ViewCache or the ViewPool, the ViewHolders in the ViewCache retain some of their state including the Position they were attached to, so these can be used as it is when needed again, whereas the ViewHolders in the ViewPool are dirty, they do retain some of their state but they need to be invalidated and rebound before being reused.

You can set a custom ViewCache size for your RecyclerView using the setItemViewCacheSize() method. When creating an App where scrolling up and down occurs often then try setting a larger size of the ViewCache because the ViewHolders in the ViewCache retain their state and can be reused at it is, so rebinding won’t be required while scrolling and the User Experience will be smooth.

Comments

Popular posts from this blog

Looper What is looper? Looper is a class which is used to execute the Messages(Runnables) in a queue. Normal threads have no such queue, e.g. simple thread does not have any queue. It executes once and after method execution finishes, the thread will not run another Message(Runnable). Where we can use Looper class? If someone wants to execute multiple messages(Runnables) then he should use the Looper class which is responsible for creating a queue in the thread. For example, while writing an application that downloads files from the internet, we can use Looper class to put files to be downloaded in the queue. How it works? There is prepare() method to prepare the Looper. Then you can use loop() method to create a message loop in the current thread and now your Looper is ready to execute the requests in the queue until you quit the loop.