Storing objects nonpersistently
The runtime store provides a central location for apps to store and share information on a smartphone. Data in the runtime store is not saved when the smartphone is restarted. The RuntimeStore API was introduced with BlackBerry® Device Software 3.6.
The runtime store is implemented in the net.rim.device.api.system.RuntimeStore class.
Objects are stored using a key-value pair. When you store an object in the runtime store, you assign the object a unique ID of type long and later use the ID to retrieve the object from the store. You can generate the unique ID in the Eclipse® editor by right-clicking the fully-qualified class name and clicking Convert 'name' to long.
Common uses of the runtime store
You can use the runtime store to store any object, and you can retrieve the object from a different process or a different app. You can also restrict access to data.
Here are some common uses of the runtime store:
| Implement system-wide singletons |
An app might require one or more singleton objects to be accessed from within the app itself or by other apps. |
Share data between two apps |
For example, an application suite could be made up of multiple apps, all of which use data that is pushed to the device. One of the apps receives all the push data and shares it with the other apps by temporarily storing the data in the runtime store. The runtime store could also be used to set up communication between a listener (such as a PushListener) and a running app. |
| Store a reference to an object for later use |
For example, an app that allows a BlackBerry device user to add and remove an ApplicationMenuItem could use the runtime store to store a reference to an ApplicationMenuItem it has registered. After the app is closed and re-opened, the ApplicationMenuItem can be accessed and unregistered. |
- Security of the runtime store
- Add an object to the runtime store
- Replace an object in the runtime store
- Retrieve the runtime store
- Retrieve a registered runtime object
- Retrieve an unregistered runtime object
- Code sample: Storing a String in the runtime store
- Code sample: Getting a stored String from the runtime store
- Code sample: Creating a singleton using the RuntimeStore API