Gary Kipnis
Gary Kipnis

Reputation: 732

How can I tell when a fragment is ABOUT to become invisible

I have a ViewPager adapter controlling fragments that display various information. When a fragment is about to be swiped out and become invisible, I'd like to receive a notification. For the Fragment class, there are functions being fired off when the fragment view or fragment is about to be destroyed, but the fragment is not destroyed, just not visible, so I am not getting any notifications.

Thank You, Gary

Upvotes: 0

Views: 242

Answers (1)

Mei-Lin
Mei-Lin

Reputation: 286

Just like Activity, the Fragment gets a callback in onPause() when the fragment is able to become invisible. So, you can implement onPause() in your fragment class to get notification. Hope it helps.

Upvotes: 1

Related Questions