AbAppletic AbAppletic - 1 year ago 109
Android Question

Android passing parameters using Bundle is returning null

I pass a parameter to my new activity in android:

Intent intent = new Intent(this,InOccasion.class);
intent.putExtra("key",key); //I've checked an seen that in this activvity "key" isn't null

As I said,
in this block isn't null.

However, when I retrieve it:

Bundle b = getIntent().getExtras();
if (b!=null)
key = b.getString("b");

and is causing a NullPointerException. However, I'm sure
isn't null. And yes, I am calling from the correct activity.

I've seen this but it's unanswered and mine is ALWAYS null.

Answer Source

You are setting they key name "key" and getting "b". Get the right key i.e. "key"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download