gpt4 book ai didi

android - 避免使用多进程和应用程序 onCreate 崩溃

转载 作者:行者123 更新时间:2023-11-29 17:17:03 25 4
gpt4 key购买 nike

来自 Firebase docs他们说:

Multiple processes

Crash Reporting creates a separate background process to upload crash info. If your app extends the Android Application class, you must ensure it is multi-process safe. Otherwise, it may cause concurrency issues. When an app extends an Application object, this object gets instantiated for each process in a multi-process app. Two important things to watch for are:

If the implementation of this object accesses any out-of-process state (a database, the file system, shared preferences, etc), or performs other actions not safe for a multi-process environment, concurrency issues might arise. This is because multiple instances of the Application object may run simultaneously. Many third-party libraries keep out-of-process state (e.g. in a local database) and are subject to the same concurrency issues if they are initialized from the Application object. If your app fits the description above and you plan to use Crash Reporting in your app, we strongly encourage you to consider moving the Application logic to Content Providers, or to Android Activities. Any Application logic that is not safe for a multi-process environment can have unintended effects on your app.

如果 Application onCreate 中有另一个实例,我如何从我的 Application class 中检查以避免崩溃使用 Fabric 还是其他?

最佳答案

一般来说,您不会“检查”是否有来自另一个进程的另一个 Application 对象。您只需假设始终为应用程序中的每个进程创建一个 Application 对象,并自行确保与其他进程中的其他 Applications 对象一起运行是安全的。只是不要从应用程序访问任何共享的读/写资源,你会没事的。

如果您必须仅从主进程初始化某些东西,更可靠的方法是创建一个 ContentProvider(在您的 list 中声明并像任何其他组件一样为它创建一个对象),并使用它的 onCreate()。 ContentProvider 仅从主进程创建和初始化——从不从其他进程创建和初始化。这样您就可以确保您的 init 不会在任何其他进程中被复制。

或者如果您根本不想处理这个问题,只需等到崩溃报告从测试版出来到完全发布,因为它在将来不会使用额外的过程。我们 (Google) 无法确切说明那会是什么时候,但我们不会浪费任何时间来发布完整版本。

关于android - 避免使用多进程和应用程序 onCreate 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38422117/

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