Sora Sora - 3 months ago 9
Android Question

sending Uri from activity to another

I have this code :

Activity 1

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri fileUri = data.getData();
Log.d("File", "File Uri: " + fileUri.toString());

Intent intent = new Intent(getContext(),activity_file_sharing.class);
intent.putExtra("Filepath", fileUri);
startActivity(intent);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}


In activity_file_sharing

Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("Filepath")) {
FPath = Uri.parse(getIntent().getStringExtra("Filepath").toString());

}


FPath = Uri.parse(getIntent().getStringExtra("Filepath").toString());


I am always getting a null reference on the line above , i can't figure out what is the problem

I hope you guys can help

Answer

Save it as a String:

Intent intent = new Intent(getContext(),activity_file_sharing.class);
                intent.putExtra("Filepath", fileUri.toString());
                startActivity(intent);
Comments