android small资源加载

来源:互联网 发布:2016网络写手排行榜 编辑:程序博客网 时间:2024/06/15 17:59

1:不用small 怎么获取资源

    Resouces r = context.getResources();

    获取字符串  r.getString(intValue);

    获取图片     r.getDrawable(intValue);

2:怎么获取其它package包的资源

   方法一:

   Context otherContext = context.createPackageContext(otherPackageName , Context.CONTEXT_IGNORE_SECURITY)

   Drawable result = otherContext.getResources.getIdentifier(context.getResources().getResourceName(resInt), "drawable",otherContext.getPackageName());

  

   方法二:

  通常用于跨进程获取另一个ap里面的资源

 final PackageManager pm = context.getPackageManager();        ApplicationInfo ai = pm.getApplicationInfo(resPackage, PackageManager.GET_UNINSTALLED_PACKAGES);            pm.getResourcesForApplication(ai).getResources().getDrawable(getResId(), context.getTheme());

 

  方法三:见small加载资源的方式

 

3: small加载资源的方式

    关键步骤在assetPath




small中是如何做的:在插件加载完后的postSetup方法中

 

 4:为什么不能加载插件中的资源

 

notification的加载流程

icon中的loaddrawable

 

如何支持:

stub模式

总结:

系统和small加载资源的流程(系统默认加载当前apk的资源路径,small动态添加插件的资源路径),
small编译生成资源的原理(修改插件的pkgid,防止冲突),系统无法获取small插件资源解决办法(app+stub模式)。
  
app+stub模式: stub在host plug打包中都存在,合成时会将plug中的id(host中也有的)替换成host中的id。
small支持插件so和插件jni