mardi 11 septembre 2018

Effective alternative to reflection for getting system properties

If we want to get some system property programatically, we can use either of the following 2 options

  1. Use reflection to get android.os.SystemProperties and call get method with key.
  2. call "getprop " using Runtime exec.

Using the sample app, I observed that option#1(took 1sec) is very faster than option#2(13secs). I understand that this happens because in option#2, a entirely new process will be spawned by JVM to execute the command.

Definitely many programmers tend to use option#1 for better performance reasons.

But, as mentioned in https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces, starting with Android P, android is blocking using non_SDK interfaces.

so, without using reflection, is there any way to get the system propertiy as fast as getting property with reflection?





Aucun commentaire:

Enregistrer un commentaire