Incorrect Implementation of describeContents() in LoyaltyCard Class
Aglag257 opened this issue · 3 comments
The describeContents()
method in the LoyaltyCard
class currently returns the id
of the card. According to the Android documentation, describeContents()
should return a bitmask indicating the set of special object types marshaled by the Parcelable
instance. The typical return value is 0
, as most implementations do not have any special characteristics.
Expected Behavior
describeContents()
should return 0
unless the Parcelable
includes a file descriptor or other special objects, which would be indicated by the bitmask constant CONTENTS_FILE_DESCRIPTOR
.
Actual Behavior
The method returns the id
of the LoyaltyCard
, which does not align with the expected behavior as per Android's Parcelable
interface contract.
Steps to Reproduce
Review the implementation of describeContents()
in LoyaltyCard.java
:
@Override
public int describeContents() {
return id;
}
Suggested Fix
Update the describeContents()
method in LoyaltyCard.java
to return 0
:
@Override
public int describeContents() {
return 0;
}
Supporting Documentation
Here is the relevant section of the Android developer documentation that describe the describeContents()
method and its intended use:
Please update the method to conform with the standard Parcelable
implementation practices or let me know if i misunderstood something
Thank you for considering this issue.
Sounds like you're probably right. Looks like this was added 3 years ago to fix a crash on rotation: 5ddcb0a
If you can test and confirm that your change won't break that it makes sense to change that so feel free to make a MR :)
Thank you for the quick response and for providing the commit it was added.
I will test the change and follow through with the MR