java - Reflect annotations from android activity class -


i developing api used in android. want use reflection access annotations implemented in android activity class. need reflect api. there way it?

i trying pass context api can activity class annotations are.

the annotation called action , follows:

@action(     name = "test",     description = "this test",     inputs = {"no input"},     output = {"no output"},     controlurl = "/api/v1/" ) public void testaction (){     /*      * implements here action!      */ } 

the method used reflect it:

private static void getaction() {     if (d) log.d(tag, "getaction");       class classwithaction = appcontext.getclass();      annotation[] aannotations = classwithaction.getdeclaredannotations();     for(annotation : aannotations)         log.d(tag, a.tostring());  } 

discovering classes annotated particular annotation in runtime requires, in general, classpath scanning. there no streamlined, official api doing it, though. because is, , inevitably, hack, due design of classloading system. in short, classes can, in principle, created on demand, in uncontrollable , arbitrary manner.

nevertheless, classpath jungle no means vicious , frought pitfalls, , can list classes particular property reasonably reliably. there 1 android-specific obstacle overcome, it's not bad. basically, trick list contents of classes.dex file in app's .apk archive, load classes contains 1 one , reflectively check desired property. can more details here (my other answer), , this blog post contains complete illustration of technique (it's not mine).


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -