Invoking activity that is located in a jar
I tried to invoke another activity from my main acitivty which is located in a jar file.
Class clazz = Class.forName(getPackageName() + "." + getActivityName()); startActivity(new Intent(this, clazz));
I'm doing it this way because I only know the name of the class. This works fine, but unfortunately, all resource files can't be fo开发者_Python百科und while loading the activity from the jar file. At the first occurence of loading a res file there is a ResourceNotFoundException
:
04-30 11:18:46.944: ERROR/AndroidRuntime(1749): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040006
Any hints for that?
Your JAR cannot reference resources.
To be more specific:
- Your JAR cannot contain resources
- Your Java code in the JAR cannot use
R.layout
orR.id
orR.drawable
or any of theR.
constants to refer to resources
You need to have all of your resources in the application that is reusing the JAR, and your JAR's Java code needs to either have resource IDs passed into it (e.g., via method parameters) or use getIdentifier()
to find out the resource ID at runtime from a String
representation of the name.
精彩评论