GetIntent (). getStringExtra () shows null

I use one EditText field and one counter. I must convey the results of both of the following. here reqd_bloodgroup is a spinner element that I converted to String using: reqd_bloodgrp = String.valueOf (spinner.getSelectedItem ()); inside onItemSelected () counter.

intent.putExtra("city", citySelected.getText().toString());
intent.putExtra("bloodgroup", reqd_bloodgrp);
intent = new Intent(FindDonor.this,SpecificDonor.class);
startActivity(intent);

Here, when I try to display them, there are no problems. They are displayed correctly. But when I try to find them in SpecificDonor, they show null values. The code used here is:

String text_city,text_bloodgroup;
text_city = getIntent().getStringExtra("city");
text_bloodgroup = getIntent().getStringExtra("bloodgroup");
Toast.makeText(getApplicationContext(), text_city + " " + "bloodgrp: " + text_bloodgroup, Toast.LENGTH_SHORT).show();

What could be the problem?

+5
source share
1 answer

I think you should do:

intent = new Intent(FindDonor.this,SpecificDonor.class);

before adding extra features. Try:

intent = new Intent(FindDonor.this,SpecificDonor.class);
intent.putExtra("city", citySelected.getText().toString());            
intent.putExtra("bloodgroup", reqd_bloodgrp);
startActivity(intent);
+7
source

All Articles