Recently, I got a strange bug report on one of our Android app. User’s favorite items are “removed” every time the app get killed. This issue really frustrated me since it took me a whole day without any clue on what’s going on. The favorites work well as expected until the app restarts, they’re gone — or in my phone, only one arbitrary favorite item left. Let’s see how I fixed it.
“There are only two hard things in Computer Science: cache invalidation and naming things.”
– Phil Karlton
Cache is hard to done right. Here I will highlight some problems we often face when dealing with caching.
As android engineer, we must already used ListView a lot if we want to show multiple items that has same template.
But there are some problems that can’t be solved by only using ListView:
1. Normally, we can only handle whole item click.
2. It’s hard to use different layout in ListView item without using ViewHolder pattern.
3. It’s become harder to handle some action within the item layout because of reason 1.
But that’s the reason why RecyclerView comes.
Programming is part of our lives as engineer. Adit, one of our experienced engineer, gave us some hints to do an efficient programming.