How to pass a URI to an intent?

前端 未结 8 788
日久生厌
日久生厌 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:03

    The Uri.parse(extras.getString("imageUri")) was causing an error:

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.putExtra(java.lang.String, android.os.Parcelable)' on a null object reference 
    

    So I changed to the following:

    intent.putExtra("imageUri", imageUri)
    

    and

    Uri uri = (Uri) getIntent().get("imageUri");
    

    This solved the problem.

提交回复
热议问题