I’ve used putExtra() to pass some data from one activity to other. I want to create a Parcelable instance but I am getting a null object.
Here is the code of first activity:
i = new Intent(Activity1.this, Activity2.class);
i.putExtra(com.login_app.Activity1.extra, "100");
startActivity(i);
Here is the code of second activity:
Intent inew = getIntent();
Bundle icicle1 = inew.getExtras();
// this is just a debug code
System.out.println(
icicle1.getSerializable(com.login_app.Activity1.extra).toString());
Parcelable p = inew.getParcelableExtra(com.login_app.Activity1.extra);
Here object p is a null object.
Please tell me if I am wrong or I need to add something else. I want this Parcelable object to be flattened into a Parcel object.
That’s because you’ve put
String, but trying to getParcelable. You should usegetStringExtrainstead.Also, from
Bundledocumentation of[getParcelable()][1](this function is used to actually get extra fromIntent‘s bundle):So you basically get
nullbecause you have type mismatch.