I want to do this
class A extends Activity{
private class myClass{
}
myClass obj = new myClass();
intent i = new Intent();
Bundle b = new Bundle();
b.putParcelable(Constants.Settings, obj); //I get the error The method putParcelable(String, Parcelable) in the type Bundle is not applicable for the arguments (int, A.myClass)
i.setClass(getApplicationContext(),B.class);
startActivity(i);
}
How do I use Parcelable to pass obj to activity B?
As the error suggests, you need to make your class (
myClassin this case) implementParcelable. If you look at the documentation forBundle, all theputParcelablemethods take either aParcelableor a collection of them in some form. (This makes sense, given the name.) So if you want to use that method, you need to have aParcelableinstance to put in the bundle…Of course you don’t have to use
putParcelable– you could implementSerializableinstead and callputSerializable.