/** * 构造插件信息 * * @param */ static void ensurePluginInited(PluginDescriptor pluginDescriptor) { if (pluginDescriptor != null) { DexClassLoader pluginClassLoader = pluginDescriptor.getPluginClassLoader(); if (pluginClassLoader == null) { LogUtil.d("正在初始化插件Resources, DexClassLoader, Context, Application "); LogUtil.d("是否为独立插件", pluginDescriptor.isStandalone()); Resources pluginRes = PluginCreator.createPluginResource( sApplication, pluginDescriptor.getInstalledPath(), pluginDescriptor.isStandalone()); pluginClassLoader = PluginCreator.createPluginClassLoader( pluginDescriptor.getInstalledPath(), pluginDescriptor.isStandalone()); Context pluginContext = PluginCreator.createPluginApplicationContext( pluginDescriptor, sApplication, pluginRes, pluginClassLoader); pluginContext.setTheme(sApplication.getApplicationContext().getApplicationInfo().theme); pluginDescriptor.setPluginContext(pluginContext); pluginDescriptor.setPluginClassLoader(pluginClassLoader); // 使用了openAtlasExtention之后就不需要Public.xml文件了 // checkPluginPublicXml(pluginDescriptor, pluginRes); callPluginApplicationOnCreate(pluginDescriptor); LogUtil.d("初始化插件" + pluginDescriptor.getPackageName() + "完成"); } } }
public static Context getNewPluginContext(Context pluginContext) { if (pluginContext != null) { pluginContext = PluginCreator.createPluginApplicationContext( ((PluginContextTheme) pluginContext).getPluginDescriptor(), sApplication, pluginContext.getResources(), (DexClassLoader) pluginContext.getClassLoader()); pluginContext.setTheme(sApplication.getApplicationContext().getApplicationInfo().theme); } return pluginContext; }
/** * 根据当前class所在插件的默认Context, 为当前插件Class创建一个单独的context * * <p>原因在插件Activity中,每个Activity都应当建立独立的Context, * * <p>而不是都使用同一个defaultContext,避免不同界面的主题和样式互相影响 * * @param clazz * @return */ public static Context getNewPluginContext(@SuppressWarnings("rawtypes") Class clazz) { Context pluginContext = getDefaultPluginContext(clazz); if (pluginContext != null) { pluginContext = PluginCreator.createPluginApplicationContext( ((PluginContextTheme) pluginContext).getPluginDescriptor(), sApplication, pluginContext.getResources(), (DexClassLoader) pluginContext.getClassLoader()); pluginContext.setTheme(sApplication.getApplicationContext().getApplicationInfo().theme); } return pluginContext; }