In this post we will learn about the Samsung Widget Persistence Library.
When we are developing widgets, we have just two functions for saving and retrieving info:
Saving: widget.setPreferenceForKey(value, key)
Retrieving: widget.preferenceForKey(key)
The functions use a lower case "widget" object. Note that we save the information with "value", "key" (in this order).
widget.setPreferenceForKey(value, key);
Saves a value with a specified key in the mobile device. The value is retained even if a device is turned off.
Parameters
value The value to be saved.
key The key that will be used to retrieve the value.
Example
In the following function call, the value "Eduardo#Brazilian#28" is saved in a key named "user_info".
widget.setPreferenceForKey ("Eduardo#Brazilian#28", "user_info");
widget.preferenceForKey(key);
Returns the value associated with the specified key. If no value is associated with the key, this function returns NULL.
Parameters
key The key that is associated with the value to be retrieved.
Example
try
{
return widget.preferenceForKey("user_info");
}
catch(e)
{
return null;
}
Easy? You can find more about Samsung Widget API here!
NOTE: You must debug your code without any API code. If you want to debug your code, remove/comment persistence code. The browser, outside IDE, don't know about Samsung API.
Thanks for your visit! :)
Next post: Let's get it started (bada)...
Feel free to ask/suggest/comment.
Twitter: @oliveiraeduardo
Nenhum comentário:
Postar um comentário