How to pass a URI to an intent?
I'm trying to pass a URI-Object to my Intent in order to use that URI in another activity.
How do I pass a URI?
private Uri imageUri;
....
Intent intent = new Intent(this, GoogleActivity.class);
intent.putExtra("imageUri", imageUri);
startActivity(intent);
this.finish();
How do I use now this URI in my other activity?
imageUri = extras.getString("imageUri"); // I know thats wrong ...
you can store the uri as string
intent.putExtra("imageUri", imageUri.toString());
and then just convert the string back to uri like this
Uri myUri = Uri.parse(extras.getString("imageUri"));
The Uri
class implements Parcelable
, so you can add and extract it directly from the Intent
// Add a Uri instance to an Intent
intent.putExtra("imageUri", uri);
// Get a Uri from an Intent
Uri uri = intent.getParcelableExtra("imageUri");
You can use the same method for any objects that implement Parcelable
, and you can implement Parcelable
on your own objects if required.