BlackBerry 应用程序开发者指南 第二卷:高级--第13章 应用程序间共享运行时对象


作者:Confach 发表于 2006-04-29 20:30 pm
版权信息:可以任意转载, 转载时请务必以超链接形式标明文章原始出处 和作者信息.
http://www.cnblogs.com/confach/articles/388976.html

13

         第13 应用程序间共享运行时对象



共享运行时对象

共享运行时对象

: 当应用程序第一次访问运行时存储时,检查一个 NoClassDefFoundError.如果系统管理员通过应用程序控制限制访问运行时存储,将抛出此错误. 为获得更多信息,参看BlackBerry应用程序开发者指南 2:高级 1:基础.

BlackBerry设备使用一个运行时存储提供一个中心位置,在此位置上应用程序可以共享运行时对象.缺省的,仅由RIM数字签名的应用程序才可以访问运行时存储上的数据.联系RIM获得关于如何控制访问你的数据的信息.

获取运行时存储

>调用RuntimeStore.getRuntimeStore().

RuntimeStore store = RuntimeStore.getRuntimeStore();

为增加或获得运行时对象,调用RuntimeStore上的方法.

:运行时存储不是持久的,如果BlackBerry重启,运行时存储的数据将丢失.

增加一个运行时对象

>调用RuntimeStore.put(long, String). 将一个唯一long ID和存储的对象作为参数.

RuntimeStore store = RuntimeStore.getRuntimeStore();

// Create an object and a unique number to identify the object.

String msg = "Some shared text";

long ID = 0x60ac754bc0867248L;

// put() throws an IllegalArgumentException if an object with the same ID exists.

try {

    store.put( ID, msg );

    }

catch(IllegalArgumentException e) {

    // Handle exception - an object with the same ID exists.

}

替换一个运行时对象

>调用 replace().

RuntimeStore store = RuntimeStore.getRuntimeStore();

String newmsg = "Some new text";

try {

    // Returns the existing object with the specified ID if it exists; null

    // otherwise.

    Object obj = store.replace( 0x60ac754bc0867248L, newmsg);

}

catch(ControlledAccessException e) {

    // Handle exception - insufficient permissions.

}

获取一个注册的运行时对象

>调用RuntimeStore.get(). 将对象ID作为参数.

RuntimeStore store = RuntimeStore.getRuntimeStore();

// get() throws a ControlledAccessException if your application does not have read access to the specified object.

try {

    // get() returns the objectm with the specified ID if it exists; null

    // otherwise.

    Object obj = store.get(0x60ac754bc0867248L);

}

catch(ControlledAccessException e) {

    // Handle exception.

}

获取一个未注册的运行时对象

>调用RuntimeStore.waitFor() 等待一个运行时对象注册.

RuntimeStore store = RuntimeStore.getRuntimeStore();

try {

    Object obj = store.waitFor(0x60ac754bc0867248L);

}

catch(ControlledAccessException e) {

    // Handle exception - insufficient permissions.

}

catch(RuntimeException e) {

    // Handle exception - time out.

}

 

 如果指定ID的对象不存在, waitFor()会阻止一个MAX_WAIT_MILLIS的最大数.如果此时对象还没有注册, waitFor()将会抛出一个RuntimeException异常.


Last Updated:2007年2月6日

 

Tag标签: Blackberry,RIM,黑莓,BB

posted on 2006-04-29 20:30 Confach 阅读(773) 评论(0)  编辑 收藏 所属分类: BlackBerry


标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-07-01 15:28 编辑过
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接:

历史上的今天:
2005-04-29 .NET数据访问体系结构指南
 




导航

公告


所有文章禁止转载,若想推荐或收藏,请用链接的形式。

哈罗,作者

Shared Readings


统计

与我联系

搜索

 

常用链接

留言簿(26)

我参与的团队

我的标签

随笔分类(99)

随笔档案(93)

文章分类(79)

文章档案(82)

相册

Blogs

积分与排名

最新评论

阅读排行榜

评论排行榜

60天内阅读排行

Blackberry Document