我们的 APP 继承 Application 做了一些初始化操作,有些前台服务用不上的初始化搬到了 SplashActivity onCreate 中,为防止 SplashActivity 重建多次执行初始化,我在别的地方定义了一个静态变量标识。
具体来说:
在 Application onCreate 将初始化标记为 shouldBuild = true (默认 false )
在 SplashActivity onCreate 判断 shouldBuild,并在事成后将 shouldBuild 标记为 false
但 Picasso 仍抱怨 Singleton instance already exists.
public static void setSingletonInstance(@NonNull Picasso picasso) {
if (picasso == null) {
throw new IllegalArgumentException("Picasso must not be null.");
}
synchronized (Picasso.class) {
if (singleton != null) {
throw new IllegalStateException("Singleton instance already exists.");
}
singleton = picasso;
}
}
我从 Bugly 看到这些崩溃报告都是 APP 在后台时触发的,怀疑是 APP 被迫重建引起。
但我感觉逻辑没问题呀,有大佬知道为什么么?