简体   繁体   English

应用程式被杀死后,片段仍然存在(Android)

[英]Fragment is still alive after app has been killed (Android)

After I have put my app in background and locked the screen, my smartphone does a "clean in suspend" and, thus, my app is killed. 在我将应用程序置于后台并锁定了屏幕之后,我的智能手机执行“清理挂起”操作,因此我的应用程序被杀死了。 After re-opening the app from Recent Apps , the onCreate() method of the main activity is called. Recent Apps程序重新打开应用Recent Apps ,将调用主要活动的onCreate()方法。 The strange thing is that, the last Fragment used before putting the app in background is "still alive". 奇怪的是,在将应用程序放入后台之前使用的最后一个Fragment是“仍然有效”。 Therefore, its onActivityCreated() callback is called because the main activity is launched. 因此,由于启动了主活动,因此调用了其onActivityCreated()回调。
Is there a way to make sure that there is no fragments associated with the main activity at startup ? 有没有办法确保启动时没有与主要活动相关的片段?

Ovveride onDestroy() method and stop or pause your running threads. 覆盖onDestroy()方法并停止或暂停正在运行的线程。 For further details, check the documentation about android life cycle. 有关更多详细信息,请查看有关android生命周期的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的Android APP进程已被终止,但仍在RunningTask中 - My Android APP's process has been killed, but still in RunningTask 如果某个进程在其活动仍然存在时被杀死了怎么办? - What if a process has been killed while its activities are still alive? 应用被杀死后,ViewPager出现NullPointerException - NullPointerException with ViewPager after the app has been killed 一个进程被杀死后,能否重用一个片段? - Can one reuse a fragment after process has been killed? 操作系统终止进程后重新启动应用程序 - Restarting the app after process has been killed by the OS 活动在后台被杀死后应用程序崩溃 - App crash after activity has been killed in background 如何检测应用是否已被服务杀死? 安卓 - How to detect if the app has been killed using a service? android 为什么在调用onDestroy()方法后,Android概述屏幕仍显示应用程序? - Why does the Android overview screen still show an app after the onDestroy() method has been called? 为什么在 Android 中替换当前片段后,我的 ViewModel 仍然存在? - Why my ViewModel is still alive after I replaced current fragment in Android? Android 在系统杀死应用程序后没有重新打开以前的活动 - Android is not reopening previous activity after system has killed app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM