How to pass an array of Uri between Activity using Bundle

后端 未结 4 1775
情话喂你
情话喂你 2021-01-13 01:43

I need to pass an array of Uri to another activity, to pass an array of String I use simply

String[] images=getImagesPathString();

    Bundle b = new Bundle         


        
4条回答
  •  Happy的楠姐
    2021-01-13 02:07

    From what I know plain arrays cannot be put into Bundles. But you can put Uri-s into ArrayList and then call Bundle.putParcelableArrayList().

    example:

     ArrayList uris = new ArrayList();
     // fill uris
     bundle.putParcelableArrayList(KEY_URIS, uris);
    

    later on:

        ArrayList uris =
                bundle.getParcelableArrayList(KEY_URIS);
        for (Parcelable p : uris) {
            Uri uri = (Uri) p;
        }
    

提交回复
热议问题