I am trying to design a plugin system for my Activity. To do that I created new class called PluginClass, external to my project and into a different package, that I load with DEXClassLoader from my main app.
I can call all the PluginClass methods from the main app easily and it works fine. The problem come out when I try to access the resources of the PluginClass project. Let me explain: the PluginClass inflates a local layout into a main activity object with the method getInflatedBox done like that:
public void getInflatedBox(ViewGroup root) {
View.inflate(context, R.layout.boxeslayout, root);
this.imgBoxX = (ImageView) root.findViewById(R.id.imgBoxX);
this.imgNotify = (ImageView) root.findViewById(R.id.imgNotify);
this.txtNotify = (TextView) root.findViewById(R.id.txtNotify);
this.txtBoxXName = (TextView) root.findViewById(R.id.txtBoxXName);
this.llShadow = (LinearLayout) root.findViewById(R.id.llShadow);
}
that should inflate the layout "boxeslayout" into the root object, coming from main activity with this call (I removed the try/catch to make it readable):
Method getInflatedBox = null;
BoxX root;
Class boxesPlugin = getPlugin(); // Another main activity method,
// where I obtain the class with DexClassLoader
pgItem = boxesPlugin.newInstance();
getInflatedBox = boxesPlugin.getMethod("getInflatedBox", ViewGroup.class);
getInflatedBox.invoke( pgItem, root );
where BoxX is a custom class extending LinearLayout.
Here is where the problerm come out: I get a layout inflated into root instance, but not the layout I wanted. Practically the R.layout.boxeslayout access the local main activity resources, inflating into root the layout from the activity that happens to have the same id value.
As my PluginClass is not an activity, I can't use context.getResources. Any idea how I could force the methods of pluginclass to access the plugin resources?
thank you very much for any help.