我需要将 Uri 数组传递给另一个活动,
传递一个我简单使用的字符串数组
String[] images=getImagesPathString();
Bundle b = new Bundle();
b.putStringArray("images", images);
但使用 Uri 数组
Uri[] imagesUri=getImagesUri();
这不起作用,因为 Bundle 中没有方法“putUri(Uri x)”
我该如何解决这个问题?
据我所知,普通数组不能放入捆绑包中。但是您可以将 Uri-s 放入 ArrayList,然后调用 Bundle.putParcelableArrayList()。
example:
ArrayList<Uri> uris = new ArrayList<Uri>();
// fill uris
bundle.putParcelableArrayList(KEY_URIS, uris);
稍后的:
ArrayList<Parcelable> uris =
bundle.getParcelableArrayList(KEY_URIS);
for (Parcelable p : uris) {
Uri uri = (Uri) p;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)