你好,游客 登录 注册 搜索
背景:
阅读新闻

Android Intent 序列化反序列化

[日期:2014-02-09] 来源:Linux社区  作者:hpccn [字体:大 中 小]

上次遇到 Intent 使用用Parcel 序列化出错(见 http://www.linuxidc.com/Linux/2014-02/96336.htm),未找到出错的原因,因项目急. 找其它的解决方法:

查看Intent 的源代码, 发现类中已经实现序列化功.

序列化

intent.toURI();

反序列 化使用:

Intent.parseUri(uriString, 0);

先看序列化:

intent.toURI();

Intent intent = new Intent("cn.eben.bookshelf.VIEW");
 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

String intnetUri = intent.toURI();

//序列化后:

//#Intent;action=cn.eben.bookshelf.VIEW;launchFlags=0x10000000;end

反序列 化使用:

Intent.parseUri(uriString, 0);

        Intent i;
      try {
            i = Intent.parseUri(uriString, 0);
            context.startActivity(i);
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

简单方便.

解决上次的问题.

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款