Search code examples
androidandroid-recyclerviewlistadapterandroid-viewholder

Doing heavy work in "ListAdapter" or "RecyclerView.ViewHolder"?


I have the two classes in my Android app.

  • TestListAdapter extends ListAdapter

  • TestViewHolder extends RecyclerView.ViewHolder

My question is, should I do heavy tasks, such as special calculations of distances or processing of strings in the "TestListAdapter" onBindViewHolder() methods or the "TestViewHolder" bind Method(s)?

Which is better from a performance point of view or does it not matter?

Greetings


Solution

  • Your really heavy tasks (downloads, file loading and processing) should run in another thread, for that you should start a AsyncLoaderTask trough LoadManager and wait for the results in the ListAdapter that notify the RecyclerView that an item has been updated.

    LoadManager also have the benefit of surviving lifecycles so you can change orientation and attach a listener to the running load manager when restoring state and wait to the task to finish without starting it again.