Reputation: 8757
how can I detect when user leaves/exits a fragment? I tried using onStop()
but it also gets called when I am in the app switcher or leave the app.
I'm using kotlin for android
Upvotes: 1
Views: 1188
Reputation: 13348
Use onDestroyView() or onDetach()
onDestroyView()
Called when the view hierarchy associated with the fragment is being removed.
onDetach()
Called when the fragment is being disassociated from the activity.
or more details. Fragment lifecycle
Upvotes: 3