Monday, November 7, 2011

SystemProperties in Android: Use them in Framework c files

Hi all,
Here I am with one more android blog. We generally used Sharedpreferences in Android to share information between Activities. But what if you want to have something at the time of boot. For that there is one solution which is systemproperties, using those you can share information or values at the time of boot. So for example if you want to save some settings by user, which should be applicable at the time boot. So do following
SystemProperties.set(String key, String val) // where key is name of property
Now to retrieve it in Java files you can directly use
SystemProperties.get(String key)
But if you want it in boot time it should be in cpp files so use
property_get( String name, char* var, NULL)
/* where name is property name, var is the variable in which u want to store value last parameter is for the default value which will be assigned to var when no property set.*/
And for the java things you can check Systemproperties.java for apis for different type of data
types. Although for cpp it is only supported for string type And if you want to save any property through c files, use property_set() method.
Hope it will you too, as it was really save my day.

No comments: