I have a recyclerView
on first Activity(reads data from DB) and insert data on it from second activity(Insert data into DB).
Now I want to update that recyclerView
when Back buttonPressed
on second Activity(when back from second activity to first activity)
now what should I do?
Asked
Active
Viewed 343 times
-1

Anas Mehar
- 2,739
- 14
- 25

Mohammad_rst
- 13
- 3
-
Show some code. – PIYUSH CHUGH Jan 23 '20 at 08:10
-
First try to do some search before asking question. https://stackoverflow.com/questions/5545217/back-button-and-refreshing-previous-activity – Shubham Vala Jan 23 '20 at 08:14
-
Does this answer your question? [How to update RecyclerView Adapter Data?](https://stackoverflow.com/questions/31367599/how-to-update-recyclerview-adapter-data) – Mostafa Soliman Jan 23 '20 at 08:16
1 Answers
2
Use LiveData and Room. Whenever room database updates, it'll give trigger onChanged to LiveData. Hence, If your activity is observing the room database. You can simply call adapter.notifyDataSetChanged()
inside the observer.

Sandesh Baliga
- 579
- 5
- 20