android - Activity.onDestroy 不会破坏我的观点

标签 android

在我的 Activity 代码的一部分中,我调用 Activity.finish() 来关闭我的 Activity,然后应用程序返回到主操作系统“桌面”窗口。

但是,如果我再次单击我的应用程序图标,onCreate 似乎没有被调用,我的 View 仍然与调用 finish 时相同。

也许,我没有正确理解生命周期,但我认为 destroy 完全破坏了 Activity ,下次调用它时会调用 onCreate。

我哪里误解了这一点?

谢谢

最佳答案

In part of my Activity's code, I am calling Activity.finish() to close my activity, and the application returns to the main OS "desktop" window.

However, if I click on my application icon again, onCreate does not seem to be called (...)

是的,它被调用了。只需 Log.d,您就会看到。

and my view remains the same as when finish was called.

它可能保持不变,因为 XML 内容和所有实例化的 View 都被再次创建。但是,如果您修改代码中的内容和布局,您会看到它已恢复为默认值,如 setContentView(int layout) 中所示。

Perhaps, I'm not understanding the lifecycle correctly, but I thought that destroy completely destroyed the activity, and the next time it was invoked it would call onCreate.

正如我所说,它会调用。

关于android - Activity.onDestroy 不会破坏我的观点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8276400/

相关文章:

java - 自定义枚举也是可序列化的吗?

java - Android如何在应用程序停止时保留 native 库

android - 如何在打开cv的情况下设置透明背景以抓取输出图像?

android - 使用外部源跟踪在 3D 空间中跟踪智能手机。

c# - Xamarin.Android 中的 Android 数据绑定(bind)库

android - 在没有网站的情况下生成 Places Api key

java - 单击 PLAY 按钮 1 次时如何逐个播放所有音频文件

android - 制作一个从 tmdb.org 接收 Json 数据的应用程序

java - 我发起的共享 Activity 完成后,共享期间使用的应用程序将打开,而不是我自己的应用程序

android - 使用 PendingIntent 托管在不同进程中的服务和 Activity 之间的通信