How to pass a URI to an intent?

前端 未结 8 762
日久生厌
日久生厌 2020-11-27 11:50

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         


        
8条回答
  •  一生所求
    2020-11-27 12:26

    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.

提交回复
热议问题