using Java reflection feature in Android app
hey, does anyone have experience in developing Android app with Java reflection feature?
I am stuck with a peculiar problem , looking for help.
I have a Activity and a common class residing in the same package of my Activity, let's assume they are com.mypkg.MyActivity and com.mypkg.MyClass my code in MyActivity:
Class clazz = MyClass.class;
Constructor[] constructors1 = clazz.getDeclaredConstructors();
Class cls = java.lang.Object.class;
Constructor[] constructors2 = cls.getDeclaredConstructors();
...
okay, now my problem: the code runs fine on simulator, while on real device, constructors of those pre-built classes, such as java.lang.Object or android.widget.FrameLayout, can be retrieved correctly, but constr开发者_开发百科uctors of MyClass is always empty(i.e. constructors1.length is always zero)
I am very confused, any help?
This may be something you've tried, but are you sure your class (MyClass) is declared correctly in your AndroidManifest.xml? Perhaps your emulator is more lenient than an actual device.
精彩评论