gpt4 book ai didi

Android - 应用程序 onCreate 方法 - 它总是先被调用吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:26:37 28 4
gpt4 key购买 nike

我正在准备我的一个应用程序的新版本,并且我对我的应用程序进行了如此巨大的更改,以至于我需要在更新应用程序之后进行一些数据转换,这绝对是第一件事(在做任何其他事情之前)。我发现,最好的地方是在我的类(扩展应用程序)的 onCreate() 方法中。我测试了几次,它似乎工作正常,但后来我阅读了文档:

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, [b]which will cause that class to be instantiated for you when the process for your application/package is created[/b].

看起来我是对的,但我不太确定。你能确认/反驳吗?

最佳答案

Application 构造函数将首先被调用。然后将调用 Application::onCreate() 方法。我知道的唯一异常(exception)是如果应用程序包含一个 ContentProvider,它可以在应用程序之前接收调用。

来自这里:http://developer.android.com/reference/android/app/Application.html#onCreate()

public void onCreate ()

Added in API level 1 Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

关于Android - 应用程序 onCreate 方法 - 它总是先被调用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21484285/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com