避免使用多进程和应用程序 onCreate 崩溃
Avoid crash with multiprocess and Application onCreate
来自 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
class 检查 Application
onCreate
中是否有另一个实例以避免崩溃与 Fabric
或其他人?
一般来说,如果有来自另一个进程的另一个 Application 对象,您不需要 "check to see"。您只需假设您的应用程序中的每个进程始终恰好创建了一个 Application 对象,并自行确保 运行 与其他进程中的其他 Applications 对象一起使用是安全的。只是不要从应用程序访问任何共享的 read/write 资源,你会没事的。
如果你必须只从主进程初始化一些东西,一个更可靠的方法是创建一个 ContentProvider(在你的清单中声明并像任何其他组件一样为它创建一个对象),并使用它的 onCreate( ). ContentProvider 仅从主进程创建和初始化——从不从其他进程创建和初始化。这样你就可以确保你的 init 不会在任何其他进程中被复制。
或者,如果您根本不想处理这个问题,只需等到崩溃报告从测试版出来到完全发布,因为它以后不会使用额外的过程。我们 (Google) 不能确切地说出什么时候发布,但我们不会浪费任何时间来发布完整版本。
来自 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
class 检查 Application
onCreate
中是否有另一个实例以避免崩溃与 Fabric
或其他人?
一般来说,如果有来自另一个进程的另一个 Application 对象,您不需要 "check to see"。您只需假设您的应用程序中的每个进程始终恰好创建了一个 Application 对象,并自行确保 运行 与其他进程中的其他 Applications 对象一起使用是安全的。只是不要从应用程序访问任何共享的 read/write 资源,你会没事的。
如果你必须只从主进程初始化一些东西,一个更可靠的方法是创建一个 ContentProvider(在你的清单中声明并像任何其他组件一样为它创建一个对象),并使用它的 onCreate( ). ContentProvider 仅从主进程创建和初始化——从不从其他进程创建和初始化。这样你就可以确保你的 init 不会在任何其他进程中被复制。
或者,如果您根本不想处理这个问题,只需等到崩溃报告从测试版出来到完全发布,因为它以后不会使用额外的过程。我们 (Google) 不能确切地说出什么时候发布,但我们不会浪费任何时间来发布完整版本。