Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intent.getStringExtra() returns null

This is how strings are being added to Extras:

Intent i = new Intent();
i.putExtra("Name", edt_name.getText());
i.putExtra("Description", edt_desc.getText());
i.putExtra("Priority", skb_prior.getProgress());
setResult(RESULT_OK, i);
finish();

This is how I try to extract them in onActivityResult():

String name = data.getStringExtra("Name");
String desc = data.getStringExtra("Description");
int prior   = data.getIntExtra("Priority", 50);

But after the second code block name and desc are null's, though prior has it's proper value. Moreover, in debugger I can see, that data.mExtras.mMap contains needed Strings, but only after first request to it.

like image 992
hotkey Avatar asked Mar 21 '13 18:03

hotkey


1 Answers

When you insert your Extras trying adding .toString()

i.putExtra("Name", edt_name.getText().toString());

You are seeing the CharSequence value in there but you need to convert it to a String to call getStringExtra(). Obviously, just do this for the Strings. You see the correct value for your int because that is done correctly

like image 99
codeMagic Avatar answered Oct 06 '22 21:10

codeMagic