您的位置:首页 > 移动开发 > Android开发

Android之Intent 序列化反序列化

2016-05-14 16:17 417 查看
        我们做截屏功能的时候,因为有2个进程,本来是把intent和MediaProjection放到Application里面,但是由于跨进程了,所以数据拿不到,就采用了Parcel 序列化出错,未找到出错的原因,找其它的解决方法:

  

查看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;
ry {
i = Intent.parseUri(uriString, 0);
context.startActivity(i);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: