通过RuntimeStore让应用程序互相交换数据

RuntimeStore里面可以根据键值存储Java对象数据,这些数据可以在不同Java Application直接共享,A application存储或者修改了数据,B Application可以读取到;反之亦然。

 

详细使用方法见BlackBerry sample application - MessageListDemo。

 

注意:RuntimeStore的键值需要32的长整型,千万不能偷懒,比如设置 private static final long MSG_KEY = 1234L;

 

public final class MessageListDemoStore {

 

...

private static final long MSG_KEY = 0xcf2b552e0e98a715L;

...

 

  /**
     * Gets the singleton instance of the MessageListDemoStore.
     * @return The singleton instance of the MessagelistDemoStore
     */
    public static synchronized MessageListDemoStore getInstance()
    {
        // Keep messages as singleton in the RuntimeStore.
        if( _instance == null )
        {
            RuntimeStore rs = RuntimeStore.getRuntimeStore();
           
            synchronized( rs )
            {
                _instance = (MessageListDemoStore) rs.get( MSG_KEY );//能get也能put哦
               
                if( _instance == null )
                {
                    _instance = new MessageListDemoStore();
                    rs.put( MSG_KEY, _instance );
                }
            }
        }       
        return _instance;
    }

你可能感兴趣的:(通过RuntimeStore让应用程序互相交换数据)