SwiftiSwift
SwiftiSwift

Reputation: 8757

Detect when user exits a fragment

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

Answers (1)

Sasi Kumar
Sasi Kumar

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

Related Questions