简体   繁体   中英

onDetachedFromWindow Never get Called for a View

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?

You want to override onWindowVisibilityChanged(int visibility) . Mainly you'd be interested in visibility = VISIBLE and visibility = GONE .

您可以在活动中覆盖onPause()并在其中进行操作。当您的活动不再对用户可见时,将调用此函数

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM