user1251064 user1251064 - 1 year ago 71
Android Question

Using a intent to pass the paths of files, but how to get the path of each file in the other activity?

Using this code to pass the paths of some files, but my problem is how to get on the other activity,each path one by one ?

Thank you.

ArrayList<Uri> files3 = new ArrayList<Uri>();

for (int i = 0; i < thumbnailsselection.length; i++) {
if (thumbnailsselection[i]) {
File file = new File(filePaths.get(i).getPath());
files3.add(Uri.fromFile(file));

}
}

Intent intentmove = new Intent(getActivity(), Main.class);
intentmove.putExtra("files", files3.toString());
startActivity(intentmove);

Answer Source

In first Activity,

Intent intentmove = new Intent(getActivity(), Main.class);
intentmove.putParcelableArrayListExtra("files", files3);
startActivity(intentmove);

And in next activity,

ArrayList<Parcelable> uris =
        getIntent().getParcelableArrayListExtra("files");
for (Parcelable p : uris) {
    Uri uri = (Uri) p;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download