Question: Hi I have created a Custom Button Class by extending the Button class.
I had overridden the `onAttachedToWindow` and `onDetachedFromWindow` methods. Now the problem is `onDetachedFromWindow` never invoked.
Below is the use case.

1. Launch Activity Containing your Custom Button class.
2. Click on Home Button. Now you are on Home Screen of Your mobile.
3. `onDetachedFromWindow` not called.

We should get callback when activity is no longer visible to the user. since activity lost it's window and no more attached to window.

Can anyone please help regarding this issue?

Answer: 
You want to override `onWindowVisibilityChanged(int visibility)`. 
Mainly you'd be interested in `visibility = VISIBLE` and `visibility = GONE`.
you can just override `onPause()` in your activity,and do things in it.this function will be called when your activity is no longer visible to the user