2

Task used in Firebase has method addOnSuccessListener(Activity, OnSuccessListener). The listener added using this method is automatically removed during activity's onStop().

What is the nearest equivalent for fragment? I.e. I want to add a listener inside a fragment but don't keep it after the fragment is closed.

Pavel
  • 5,374
  • 4
  • 30
  • 55
  • The reason why I need it is described in [this question](https://stackoverflow.com/q/53510119/6131611) – Pavel Dec 04 '18 at 00:02

1 Answers1

1

You can use LiveData & ViewModel:

  1. create ViewModel & "Success Event" LiveData in ViewModel
  2. observer that liveData from your fragment
  3. when receiving OnSuccessListener() -> update the above LiveData content
h0102
  • 236
  • 3
  • 11