Android E/Parcel﹕ Class not found when unmarshalling (only on Samsung Tab3)
In my case, new Intent().putExtra(key,parcelable) which internally auto creates new bundle gives me unmarshall error I don't know why, so I had to create new bundle by myself, add the parcelable on it and add the bundle on the intent. By doing so it solves the problem.
For some strange reason it looks like the class loader isn't set up properly.
Try one of the following in TestActivity.onCreate()
:
TestParcel cfgOptions = getIntent().getParcelableExtra("cfgOptions");
Intent intent = getIntent();
intent.setExtrasClassLoader(TestParcel.class.getClassLoader());
TestParcel cfgOptions = intent.getParcelableExtra("cfgOptions");
Bundle extras = getIntent().getExtras();
extras.setClassLoader(TestParcel.class.getClassLoader());
TestParcel cfgOptions = extras.getParcelable("cfgOptions");
Alternatively, wrap the parcelable into a bundle:
Bundle b = new Bundle();
b.putParcelable("options", cfgOptions);
Intent intent = new Intent(MDex.this, TestActivity.class);
intent.putExtra("bundle", b);
to get:
Bundle b = getIntent().getBundleExtra("bundle");
TestParcel cfgOptions = b.getParcelable("options");
Just trying to be more concise and clear of the answer here -
//sending a parcelable class to another activity -----------------
MyParcelableOptionsClass mpoc = new MyParcelableOptionsClass();
Bundle b = new Bundle();
b.putParcelable("options", mpoc );
Intent intent = new Intent(MyActivity.this, OtherActivity.class);
intent.putExtra("bundle", b);
startActivityForResult(intent, 1);
//getting the parcelable class from OtherActivity------------------
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other_activity);
Bundle b = getIntent().getBundleExtra("bundle");
MyParcelableOptionsClass mpoc = b.getParcelable("options");
}
//returning the parcelable class back from OtherActivity -----------
Bundle b = new Bundle();
b.putParcelable("options", mpoc);
Intent intent = new Intent();
intent.putExtra("bundle", b);
setResult(0, intent);
//and getting the parcelable class back in MyActivity --------------
onActivityResult(int requestCode, int resultCode, Intent data){
if(null != data){
Bundle b = data.getBundleExtra("bundle");
MyParcelableOptionsClass mpoc = b.getParcelable("options");
}
}