Search code examples
javaandroidkotlinmobilebackend

Efficient Ways To Display Messages In RecyclerView


I want to store user messages in a RecyclerView permanently without saving them to the storage. All messages are coming from a server, and I want to permanently save them to a RecyclerView. That is, I want to ensure that RecyclerView messages do not disappear even after the activity is relaunched.

Is there any way for this approach without saving the messages to the storage?


Solution

  • RecyclerViews don't save anything. They're a display element. You have to explicly write an Adapter for every RecyclerView that defines how many elements there are, how to get it's data, and how to display a single item in it. So your question is off from the beginning- RecyclerViews don't store data.

    But in order to do what you want, you need some way of getting the data. That can be reading from storage, or a database, or reading from an external source like a website. But something somewhere needs to be storing it in order to keep the data persistent between runs.