Monday, 15 February 2021

How to update RecyclerViews in Android in a ClientServer architecture with single activity and mutiple fragments

I would like to create an App that has clients and a server (so basically they are 2 different apps). In each of the Clients (and the servers) I use a single-activity-multiple-fragments approach and in each App I have a SQLite database. In some fragments I use a RecyclerView. Now the server should be able to update the recylerview in each individual client (and the database) separately and vice versa, meaning that the clients should be able to trigger an update of the recyclerView and databases of the server.

Now my question is, how can I generally do this in Android? I did an Internet search and often for communication within an app between different fragments the ViewModel and LiveData approach is used. Now I am wondering, if I can also use these approaches for my purposes? I also found an official Android developer page about communcation between Apps https://developer.android.com/training/basics/intents but here they are using intents and I think that they do not use the single-activity-multiple-fragments approach.

So is it possible to use the ViewModel and LiveData approach for that or do I have to use the intent-approach?

Update: I was told that I can't use the ViewModel or LiveData for my purposes. Do you have an idea how I can do what I want? So the clients should be able to send something to the server and the server should be able to send information to the database of the clients and based on that the clients should update their Recyclerview. Can I use sockets for that?

Does nobody have a further idea how I can implement this? As I am struggeling on this question I would highly appreciate your comments and would be quite thankful for your help.

Here you can see a rough sketch of the app architecture.enter image description here



from How to update RecyclerViews in Android in a ClientServer architecture with single activity and mutiple fragments

No comments:

Post a Comment