I have two activities which share an exact same list, ListA
, that has a property called amount
.
In my first activity, I have:
RecyclerView
with ViewHolder
s. Inside each of this ViewHolder
, I have a button to manipulate the amount
of an item in ListA
(each ViewHolder
has an item inside ListA
which is associated with it). This RecyclerView
has two types of ViewHolder
: Header
and Item
. The Item
ViewHolder
shows the amount
of the item inside ListA
it is associated with.Button
to go to the second activityIn my second activity, I have:
ListA
) copy (passed using Intent
and Parcelable
)RecyclerView
that is basically the same (information-wise) as the one in first activity with added functionalities. One of the functionalities includes manipulating the amount
of an item in ListA
. However, this RecyclerView
only has one ViewHolder
type (without Header
). Also, there are some extra layouts that are present in the Item
ViewHolder
(because of the added functionalities).Button
to return to the first activityI want to:
ListA
from first activity to second activity and vice-versaRecyclerView
's ViewHolders
when second activity manipulates ListA
and goes back to first activity; and vice-versaWhat is the best way to do this? Currently, I'm passing ListA
as a Parcelable Intent
to second activity. However, I found it hard to update the UI accordingly on my first activity's RecyclerView
s Item ViewHolder
. This is because the callback passed to update its Item ViewHolder
's UI requires the specified id of the layout that represents amount
is triggered by the button press (in onBindViewHolder
), which I am not pressing when I'm returning to the first activity.
Room with live data resolve your problem. https://developer.android.com/topic/libraries/architecture/livedata If you don't wanna use internal database you could try use 2 Fragments in one Activity instead of 2 Activity and manage data in the activity(or it's presenter, viewmodel ect...)