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