Android使用Intent传递复杂参数及复杂参数列表刚开始一直纠结于Intent只能put像int, String之类的简单参数
Android使用Intent传递复杂参数及复杂参数列表
刚开始一直纠结于Intent只能put像int, String之类的简单参数, 知道最近才发现了一下的方法.
一>, 使用Intent传递实体类对象
首先实体类需要
implements Serializable然后
?
?
Intent broadIntent = new Intent();Bundle bundle = new Bundle();bundle.putInt("flag", C.BroadFlags.Login);bundle.putSerializable(C.BroadKey.UserInfo, userInfo);broadIntent.putExtras(bundle);就可以了.?
?
接收时:
?
RetUserInform userInfo = (RetUserInform) intent.getSerializableExtra(C.BroadKey.UserInfo);
?
?
二>, 使用Intent传递复杂参数的List
?
Intent broadIntent = new Intent();broadIntent.setAction("com.ytu.enetmobile.servicesBroadcast");Bundle castBundle = new Bundle();castBundle.putInt("flag", C.BroadFlags.GetInfo);castBundle.putSerializable(C.BroadKey.Info, list.toArray());broadIntent.putExtras(castBundle);接收
?
?
Object[] cobjs = (Object[]) intent.getSerializableExtra(C.BroadKey.Info);for(Object obj:cobjs){list.add((Info)obj);}同样也要
implements Serializable
