歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android Intent 序列化反序列化

Android Intent 序列化反序列化

日期:2017/3/1 9:48:44   编辑:Linux編程

上次遇到 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

Copyright © Linux教程網 All Rights Reserved