浏览代码

Initialize global context before MainApp.onCreate()

Initialize global context just after attaching base
context.

ContentProvider depend on MainApp.getAppContext(),
but ContentProvider.onCreate() is called *before*
Application.onCreate().

This hack should improve stability of ContentProviders
at process bring-up time until we address this
with a proper DI.

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
Chris Narkiewicz 6 年之前
父节点
当前提交
2a08cb47d9
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      src/main/java/com/owncloud/android/MainApp.java

+ 8 - 2
src/main/java/com/owncloud/android/MainApp.java

@@ -49,7 +49,6 @@ import com.nextcloud.client.di.ActivityInjector;
 import com.nextcloud.client.di.DaggerAppComponent;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.AppPreferencesImpl;
-import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.PassCodeManager;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.MediaFolder;
@@ -163,9 +162,17 @@ public class MainApp extends MultiDexApplication implements
     @SuppressWarnings("unused")
     private boolean mBound;
 
+    /**
+     * Temporary hack
+     */
+    private static void initGlobalContext(Context context) {
+        mContext = context;
+    }
+
     @Override
     protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
+        initGlobalContext(this);
         DaggerAppComponent.builder()
             .application(this)
             .build()
@@ -187,7 +194,6 @@ public class MainApp extends MultiDexApplication implements
                 uploadsStorageManager
             )
         );
-        MainApp.mContext = getApplicationContext();
 
         new SecurityUtils();
         DisplayUtils.useCompatVectorIfNeeded();