[英]Activity's onDestroy method is not being called after swiping from background
i have implemented activity's lifecycle callback methods, when i swipe the activity from the background. 当我从后台滑动活动时,我已经实现了活动的生命周期回调方法。
onDestroy
method is not being called, i searched for the answers and i got one from one stating that onDestroy
方法没有被调用,我搜索了答案,并从其中得到了一个说明
"Swiping the app from the task list basically means "kill this app right now" it's not given any time to perform an onDestroy
. None of the lifecycle methods will be called" “从任务列表中擦除该应用程序基本上意味着“立即杀死该应用程序”,没有时间执行
onDestroy
。不会调用任何生命周期方法。”
But in my case, sometimes onDestroy
method is being called and sometimes not, i am unable to understand this. 但就我而言,有时会调用
onDestroy
方法,有时却不会,我无法理解这一点。
Thanks. 谢谢。
There is no guarantee that your onDestroy method will be called at all. 不能保证将完全调用您的onDestroy方法。 You can call onDestroy by calling
finish()
on your activity. 您可以通过在活动中调用
finish()
来调用onDestroy。 The system calls onDestroy only for saving space. 系统仅为了节省空间而调用onDestroy。 You can take a look here: link .
您可以在这里查看: link 。 What is important for you to know is that you have to be totally sure that this method will be called before you put some code in it.
对您来说重要的是,必须完全确保在将一些代码放入其中之前将调用此方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.