2

I'm a newbie here. I'm using bottomnavigationview in my activity(say Activity1) with three fragments. One of them contains Recyclerview which loads data from firebase and on click leads to another activity(say Activity2) using intents and passes some data with it. Now when I press back in Activity2 it returns to Activity1 which is what I want and fine, but the problem is that the Recyclerview reloads again. PS. I tried to put a button in another fragment(Just for testing purpose) which leads to same activity and on returning back from it, the activity1 retains the position, data and doesn't reload. So I guess the problem is with Recyclerview onclick.

SilverNak
  • 3,283
  • 4
  • 28
  • 44
elchicho44
  • 138
  • 7

3 Answers3

4

I managed to solve it,I had my adapter ".startlistening()" in onStart() method,I simply placed it in onCreateView() before setting up recyclerview adapter and removed onStop() method.

elchicho44
  • 138
  • 7
2

Have you tried saving and restoring your recyclerView's data in onSaveInstanceState in onRestoreInstanceState? You can also save the recyclerView scroll state as well using the linearLayoutManager.

Here's an example of how to save the recyclerView's state: https://stackoverflow.com/a/28262885/4138919

VIN
  • 6,385
  • 7
  • 38
  • 77
1

Simply remove OnResume() method. I think you are fetching data from server or database when fragment starts. So make sure not calling data on onResume() method.

Erselan Khan
  • 692
  • 6
  • 13