Android Intent 序列化反序列化

Linux大全评论838 views阅读模式

上次遇到 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();
        }

简单方便.

企鹅博客
  • 本文由 发表于 2020年3月2日 04:49:58
  • 转载请务必保留本文链接:https://www.qieseo.com/179182.html

发表评论