What is the use of the reflection API in the Android? What are its Advantages in Respect of android and why it is necessary?
Asked
Active
Viewed 4,258 times
-3
-
It might lead to a better question if you stated why you believe the answer would be *different* for Android as compared to other platforms. – Dave Newton Nov 18 '11 at 04:58
-
Same as the reflection API outside of Android. For example, [this SO question](http://stackoverflow.com/questions/37628/what-is-reflection-and-why-is-it-useful). – Dave Newton Nov 18 '11 at 04:56
1 Answers
2
In android, Google has set some APIs hidden, so we developers can't get access to these APIs directly. In that case, we can use Reflection feature in Java to call these APIs at runtime.
One typical application of Reflection I have used is to change the MOBILE DATA CONNECTION state, there is no such a public API for developers, however, we can use Reflection to make it. See here:
However, this is not encouraged, since hidden APIs would be changed in the future without notification . That means the app may not work at a higher API level.
-
2Not only can hidden APIs change or get removed in a different API level but device manufacturers are free to change or remove them within the *same* API level. You may get lucky under some circumstances but if you use hidden APIs you do so at your own risk. – adamp Nov 18 '11 at 05:34