简体   繁体   English

从后台滑动后未调用Activity的onDestroy方法

[英]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.

相关问题 通过滑动从后台删除活动后未调用Activity的onDestroy()方法 - Activity's onDestroy() method not called after removing activity from background by swiping 片段的onActivityCreated()在Activity的onDestroy()之后调用 - Fragment's onActivityCreated() is called after onDestroy() of Activity Android活动生命周期:在OnDestroy之后调用OnRestart - Android Activity Life Cycle: OnRestart being called after OnDestroy 当我启动 Activity 时,在 onCreate() 之后调用 OnDestroy() - OnDestroy() is being called after onCreate() when I start Activity 如果未调用活动的 onDestroy() 方法,如何更新远程数据库中的状态? - How to update status in remote database if the activity's onDestroy() method is not called? 在调用onDestroy()方法之后,Activity实例是否真的被破坏了? - Is the Activity instance really destroyed after onDestroy() method is called? onStop 在 onDestroy 之后被调用? - onStop being called after onDestroy? 在onHandleIntent之后立即调用IntentService的onDestroy方法 - IntentService's onDestroy method getting called straight after onHandleIntent Android中未调用OnDestroy作为后台服务 - OnDestroy not being called for background Service in Android 为什么要调用新Activity的onDestroy()? - Why new Activity's onDestroy() is called?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM