Is there a way to check for Fragment's onResume inside Recycler View Adapter class?

Viewed 215

I have a recyclerViewAdapter class where I want some logic to be performed when the onResume method is called inside my Fragment holding the adapter. This means that once a user presses the back button to return to the fragment, an operation would take place inside the adapter.

Is there a way to this?

2 Answers

There can be a couple of solutions. You can use the observer pattern here.

  1. Define a Listener and implement it on the RecyclerView Adapter class.
  2. Make a reference of the Listener from the RecyclerView Adapter Object inside Fragment.
  3. Inside onResume of Fragment, call the listener's method.

For details, check this tutorial.

You an make a method in recyclerViewAdapter and call it in onResume callback of containing fragment.

Related