本文介绍了android销毁时有视图回调吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义视图组件.我在片段或活动中都使用了它.我想知道片段/活动中销毁它时是否有回调?

I have a custom view component. I used it in either fragment or activity. I would like to know if there's a callback when it's destroyed from fragment/activity?

推荐答案

视图没有回调(finalize()除外,但我认为这不是您要的).从屏幕上将其移除时,视图具有onDetachedFromWindow(),但这与它被销毁没有关系-可以再次附加它,这将调用onAttachedToWindow().

View does not have a callback (except finalize(), but I don't think that's what you're asking for). View has onDetachedFromWindow() when it is removed from the screen, but this is not related to it being destroyed -- it could be attached again, which will call onAttachedToWindow().

片段具有onDestroyView(),这可能对您更有用. Activity没有等效的方法,但是您可以使用onDestroy(),只要您知道系统决定意外终止应用程序就永远不会调用它.

Fragment has onDestroyView(), which may be more useful to you. Activity doesn't have an equivalent method, but you could use onDestroy() as long as you know it may never be called if the system decides to terminate your app unexpectedly.

这篇关于android销毁时有视图回调吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 15:18
查看更多