简体   繁体   English

如果Activity在onCreate()之后但在onStart()之前结束,那么代替onStop()的是什么?

[英]What is called in place of onStop() if Activity is ended after onCreate() but before onStart()?

在此输入图像描述

So I have a very special scenario where I hit the back button right after onCreate() is called so it doesn't end up running onStart() and I have a bunch of code that I put into onStop() that I would need to run to clean things up at the very end but because onStart() is never executed, onStop() isn't reached. 所以我有一个非常特殊的场景,我在调用onCreate()之后立即按下后退按钮,因此它不会最终运行onStart()而且我有一堆代码,我放入onStop(),我需要运行以在最后清理,但因为从未执行onStart(),所以未达到onStop()。 Is my scenario even possible? 我的情景甚至可能吗? I tried looking at my print statements throughout the program and this is the scenario that I've come up with. 我尝试在整个程序中查看我的打印语句,这就是我想出的情景。 Assuming it is indeed possible my scenario, are there are functions that are called if the Activity ends right after onCreate() but before onStart() that I can put my clean up code into? 假设我的场景确实可能,如果Activity在onCreate()之后但在onStart()之前结束,是否可以将我的清理代码放入其中,则会调用函数吗?

Let say Class A -> Class B -> closed. 假设A类 - > B类 - >关闭。

If you are running the code from class (Class B) that doesn't even go to 'onStart()', you don't need to clean anything, since that class hasn't even started yet. 如果您正在运行类(B类)中甚至没有转到'onStart()'的代码,则不需要清理任何内容,因为该类尚未启动。

But if you want to clean something, you should consider from the previous class (Class A), in 'onStop()'. 但是如果你想要清理一些东西,你应该从'onStop()'中考虑上一个类(A类)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM