I have two objects that are identical in every way (that I am aware of) - in other words, all properties are identical.
Object A
Object B
The class implements Apache reflection is as such:
public class Base<T> {
#Override
public boolean equals(Object obj) {
try {
if (!this.getClass().isInstance(obj)) {
return false;
}
if(EqualsBuilder.reflectionEquals(this, obj)){
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
Where org.apache.commons.lang.builder.EqualsBuilder is the namespace used.
However, whenever I use this equal method to compare them, it returns false.
The objects are implementations of the following:
public class Device extends Base<Object> implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int _id = -1;
private long create_date = 0;
private long update_date = 0;
private int other_id = -1;
private String description = "";
private int configuration_id = -1;
private long sync_date = 0;
private Device_Info device_info = null;
public int get_id() {
return _id;
}
public void set_id(int _id) {
this._id = _id;
}
public long getCreate_date() {
return create_date;
}
public void setCreate_date(long create_date) {
this.create_date = create_date;
}
public long getUpdate_date() {
return update_date;
}
public void setUpdate_date(long update_date) {
this.update_date = update_date;
}
public int getOther_id() {
return other_id;
}
public void setOther_id(int other_id) {
this.other_id = other_id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getConfiguration_id() {
return configuration_id;
}
public void setConfiguration_id(int configuration_id) {
this.configuration_id = configuration_id;
}
public void setSync_date(long sync_date) {
this.sync_date = sync_date;
}
public long getSync_date() {
return sync_date;
}
/**
*
* #return
*/
public ContentValues getContentValues() {
// define an object to contain the object values
ContentValues values = new ContentValues();
try {
// set the values of each table column.
if(this.get_id() > 0){
values.put("_id", this.get_id());
}
values.put("create_date", this.getCreate_date());
values.put("update_date", this.getUpdate_date());
values.put("description", this.getDescription());
values.put("other_id", this.getOther_id());
values.put("configuration_id", this.getConfiguration_id());
values.put("sync_date", this.getSync_date());
return values;
} catch (Exception e) {
return values;
}
}
public Device_Info getDevice_info() {
return device_info;
}
public void setDevice_info(Device_Info device_info) {
this.device_info = device_info;
}
}
Device info is another class similar to the device class (an extension really), but just has more detailed properties. As previously mentioned, these two objects are identical - I set each property manually to the same value in each object and verify by checking each property individually.
This method works on more simple objects, but I do not understand why it fails on this more complex object? By complex I mean a class that has another class as a property. The Android ContentValues does not appear to affect success/fail.
Related
I'm trying to list objects that have an inner Collection. I can save and retrieve objects just fine, but when I do:
parentRepo.findAll()
Only the last object has it's child object listed, others has an empty collection.
Parent model
#ForeignCollectionField(eager = false)
private Collection<Child> childs;
Child model
#DatabaseField(foreign=true,foreignAutoRefresh=true)
private Parent parent;
eager true or false doesn't make any difference. If i query a child and get its parent, I can get it's children as well. What am I missing?
Edit:
It's working for the modeling that I made. My mistake was that I need a Many-to-many relation between parent and child. I made a quick research and what I need is an intermediate model to achieve this. I'll close this question and will try to made this many-to-many relation between my models.
I solve my Many-to-Many relationships like this:
This is an example from an ongoing project. I have a Many-to-Many relationship between Preparation and GlideWax. To solve it I use thee classes: Preparation, GlideWax and PreparationGlideWax. PreparationGlideWax represents the connections between the the other classes, just like the way you usually solve many-to-many relationships with a table that is a "link" between the tables in the relationship. As you can see GripWax and Structure also has a Many-to_many relationship to preparation. Here is the code:
GlideWax.java
#DatabaseTable(tableName = "glide_waxes")
public class GlideWax {
#DatabaseField(id = true)
private int id;
#DatabaseField(canBeNull = false)
private String name;
#DatabaseField
private String description;
#DatabaseField(canBeNull = false)
private int inUse;
#DatabaseField(foreign=true)
private WaxBrand waxBrand;
#DatabaseField(foreign=true)
private GlideWaxType glideWaxType;
#ForeignCollectionField
private ForeignCollection<PreparationGlideWax> preparationGlideWaxes;
#ForeignCollectionField
private ForeignCollection<TestSessionGlideWax> testSessionGlideWaxes;
public GlideWax() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getInUse() {
return inUse;
}
public void setInUse(int inUse) {
this.inUse = inUse;
}
public WaxBrand getWaxBrand() {
return waxBrand;
}
public void setWaxBrand(WaxBrand waxBrand) {
this.waxBrand = waxBrand;
}
public GlideWaxType getGlideWaxType() {
return glideWaxType;
}
public void setGlideWaxType(GlideWaxType glideWaxType) {
this.glideWaxType = glideWaxType;
}
public ForeignCollection<PreparationGlideWax> getPreparationGlideWaxes() {
return preparationGlideWaxes;
}
public void setPreparationGlideWaxes(ForeignCollection<PreparationGlideWax> preparationGlideWaxes) {
this.preparationGlideWaxes = preparationGlideWaxes;
}
public ForeignCollection<TestSessionGlideWax> getTestSessionGlideWaxes() {
return testSessionGlideWaxes;
}
public void setTestSessionGlideWaxes(ForeignCollection<TestSessionGlideWax> testSessionGlideWaxes) {
this.testSessionGlideWaxes = testSessionGlideWaxes;
}
}
Preparation.java
#DatabaseTable(tableName = "preparations")
public class Preparation {
#DatabaseField(generatedId=true)
private int id;
#ForeignCollectionField
private ForeignCollection<PreparationGlideWax> preparationGlideWaxes;
#ForeignCollectionField
private ForeignCollection<PreparationGripWax> preparationGripWaxes;
#ForeignCollectionField
private ForeignCollection<PreparationStructure> preparationStructures;
#DatabaseField(foreign=true, canBeNull = false)
private SkiPair skiPair;
#DatabaseField(foreign=true, canBeNull = false)
private SkiTester skiTester;
#DatabaseField(foreign=true)
private Rfid rfid;
#DatabaseField(foreign=true, canBeNull = false)
private TestSession testSession;
#ForeignCollectionField
private ForeignCollection<Measurement> measurements;
public Preparation() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public ForeignCollection<PreparationGlideWax> getPreparationGlideWaxes() {
return preparationGlideWaxes;
}
public void setPreparationGlideWaxes(ForeignCollection<PreparationGlideWax> preparationGlideWaxes) {
this.preparationGlideWaxes = preparationGlideWaxes;
}
public ForeignCollection<PreparationGripWax> getPreparationGripWaxes() {
return preparationGripWaxes;
}
public void setPreparationGripWaxes(ForeignCollection<PreparationGripWax> preparationGripWaxes) {
this.preparationGripWaxes = preparationGripWaxes;
}
public ForeignCollection<PreparationStructure> getPreparationStructures() {
return preparationStructures;
}
public void setPreparationStructures(ForeignCollection<PreparationStructure> preparationStructures) {
this.preparationStructures = preparationStructures;
}
public SkiPair getSkiPair() {
return skiPair;
}
public void setSkiPair(SkiPair skiPair) {
this.skiPair = skiPair;
}
public SkiTester getSkiTester() {
return skiTester;
}
public void setSkiTester(SkiTester skiTester) {
this.skiTester = skiTester;
}
public Rfid getRfid() {
return rfid;
}
public void setRfid(Rfid rfid) {
this.rfid = rfid;
}
public TestSession getTestSession() {
return testSession;
}
public void setTestSession(TestSession testSession) {
this.testSession = testSession;
}
}
PreparationGlideWax.java
#DatabaseTable(tableName = "preparation_glide_wax")
public class PreparationGlideWax {
#DatabaseField(generatedId=true)
private int id;
#DatabaseField(canBeNull = false)
private int layer;
#DatabaseField(foreign=true, canBeNull = false)
private GlideWax glideWax;
#DatabaseField(foreign=true, canBeNull = false)
private Preparation preparation;
public PreparationGlideWax() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getLayer() {
return layer;
}
public void setLayer(int layer) {
this.layer = layer;
}
public GlideWax getGlideWax() {
return glideWax;
}
public void setGlideWax(GlideWax glideWax) {
this.glideWax = glideWax;
}
public Preparation getPreparation() {
return preparation;
}
public void setPreparation(Preparation preparation) {
this.preparation = preparation;
}
}
As I said in the edit, I'm able to load the child from parent just fine. My problem is that I need a many-to-many relation between my models. I'll accept this answer in two days.
I have an object which I for now save using SharedPreferences like this:
public String getActiveTripString(Context con) {
return preferences.getString(ACTIVE_TRIP, "-1");
}
public void setActiveTripString(Context context, String string) {
setString(context, string, ACTIVE_TRIP);
}
public PSTrip getActiveTrip(Context context) {
String active = getActiveTripString(context);
PSTrip psTrip = null;
if (active.contentEquals("-1")) {
return null;
} else {
try{
psTrip = JsonUtil.jsonToObject(active, PSTrip.class);
}catch (Exception e){
Log.i("","getActiveTrip error is:" + e.getMessage());
}
return psTrip;
}
}
public void setActiveTrip(PSTrip psTrip, Context context) {
try{
setActiveTripString(context, JsonUtil.objectToJson(psTrip, PSTrip.class));
}catch (Exception e){
Log.i("","setActiveTrip error is:" + e.getMessage());
}
}
Where I have function as you can see, that create a json and then save it as a string in SharedPrefferences. But The object is BIG, and the more I add into it, the app start to be more laggy until it's unresponsive.
I also need to use this object in a lot of places, so I always need to call:
GetActiveTrip to get it, make my modifications, then SetActiveTrip to save it.
I'm looking for a more efficient way to save it. I tried with REALM, to save it in a database, but because my object is so big, and modified in a lot of places, I did not quite manage to make it work, Having to call Realm a lot just to add items in the database, in order to have managed database items, so I can add them in my object, and so on. Which also I think might be memory consuming. And It crashes a lot with realm exceptions.
Any other way I could do this? Is saving to a file more efficient than to Shared Preferences? As I saw in Android Monitor, analysing my traces, the GSON function that creates the JSON takes a lot of resources.
Any suggestions what I could use?
EDIT: My object:
public class PSTrip extends RealmObject {
private boolean valid;
private String type;
private String travel_mode;
#PrimaryKey
private String id;
private Owner_data owner_data;
private int distance;
private String name;
private double checkinLat;
private double checkinLng;
private double checkoutLng;
private double checkoutLat;
private String icon;
private String status;
private Destination destination;
private int checkout_time;
private int checkin_time;
private Route route;
private String owner;
private String vehicle;
private Flight flight;
#SerializedName("last_updated")
private int lastUpdated;
#SerializedName("steps")
private RealmList<TripStep> tripSteps;
private RealmList<Record> records;
#SerializedName("planned_route")
private Planned_Route plannedRoute;
private Group group;
private float emissions;
private Co2PerKm co2_per_km;
private int update_interval;
private boolean isRoaming = false;
public boolean getIsRoaming() {
return isRoaming;
}
public void setIsRoaming(boolean isRoaming) {
this.isRoaming = isRoaming;
}
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public int getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(int lastUpdated) {
this.lastUpdated = lastUpdated;
}
public RealmList<TripStep> getTripSteps() {
return tripSteps;
}
public void setTripSteps(RealmList<TripStep> steps) {
this.tripSteps = steps;
}
public String getVehicle() {
return vehicle;
}
public void setVehicle(String vehicle) {
this.vehicle = vehicle;
}
public Flight getFlight() {
return flight;
}
public void setFlight(Flight flight) {
this.flight = flight;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTravel_mode() {
return travel_mode;
}
public void setTravel_mode(String travel_mode) {
this.travel_mode = travel_mode;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Owner_data getOwner_data() {
return owner_data;
}
public void setOwner_data(Owner_data owner_data) {
this.owner_data = owner_data;
}
public int getDistance() {
return distance;
}
public void setDistance(int distance) {
this.distance = distance;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public Destination getDestination() {
return destination;
}
public void setDestination(Destination destination) {
this.destination = destination;
}
public int getCheckout_time() {
return checkout_time;
}
public void setCheckout_time(int checkout_time) {
this.checkout_time = checkout_time;
}
public int getCheckin_time() {
return checkin_time;
}
public void setCheckin_time(int checkin_time) {
this.checkin_time = checkin_time;
}
public Route getRoute() {
return route;
}
public void setRoute(Route route) {
this.route = route;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public PSTrip() {
}
public PSTrip(String id) {
this.id = id;
}
public double getCheckoutLng() {
return checkoutLng;
}
public void setCheckoutLng(double checkoutLng) {
this.checkoutLng = checkoutLng;
}
public double getCheckinLat() {
return checkinLat;
}
public void setCheckinLat(double checkinLat) {
this.checkinLat = checkinLat;
}
public double getCheckinLng() {
return checkinLng;
}
public void setCheckinLng(double checkinLng) {
this.checkinLng = checkinLng;
}
public double getCheckoutLat() {
return checkoutLat;
}
public void setCheckoutLat(double checkoutLat) {
this.checkoutLat = checkoutLat;
}
public boolean isRoaming() {
return isRoaming;
}
public void setRoaming(boolean isRoaming) {
this.isRoaming = isRoaming;
}
public Planned_Route getPlannedRoute() {
return plannedRoute;
}
public void setPlannedRoute(Planned_Route plannedRoute) {
this.plannedRoute = plannedRoute;
}
public boolean isValid() {
return valid;
}
public float getEmissions() {
return emissions;
}
public void setEmissions(float emissions) {
this.emissions = emissions;
}
public Co2PerKm getCo2_per_km() {
return co2_per_km;
}
public void setCo2_per_km(Co2PerKm co2_per_km) {
this.co2_per_km = co2_per_km;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public int getUpdate_interval() {
return update_interval;
}
public void setUpdate_interval(int update_interval) {
this.update_interval = update_interval;
}
public RealmList<Record> getRecords() {
return records;
}
public void setRecords(RealmList<Record> records) {
this.records = records;
}
}
Where: Route, Destination are the google maps object, if you are familiar with them, you know what they include and their size;
TripStep = similar with the STEP object from google BUT, it includes 2 arrays:
private RealmList<StopInfo> filteredLocations = new RealmList<>();
private RealmList<StopInfo> rawLocations = new RealmList<>();
In which I have to add a new location every 5-6 seconds in the rawLocations.
Add a new location each time the rawlocation I get is farther than x metres from the last rawLocation I got.
Getting the Object from Preferences, deserialising, getting the latest TripStep and adding the new Location to the filteredLocations and rawLocations seems to take a log of memory. So This is what I think is the problem
After all, I chose to use Realm, instead of shared preferences, it's more efficient, and even if I still have some issues with the changes I make to my file, I'm getting to a stable version quickly.
It has it's downsides (some REALM objects are not serialised correctly by GSON, and you will need to use jackson, and also not being able to use functions inside your model, or that it supports just primitives is a big issue with it, but if you manage to go over this, it's worth it)
Would not suggest adding Realm database to a project that is already big
So, I have a class for enum, like this:
public class EnumActivities {
public enum ActivitiesModeEnum {
ACTIVITY_0(0,"NONE"),
ACTIVITY_1(1, "AEROBICS"),
ACTIVITY_2(2, "CYCLING"),
ACTIVITY_3(3, "RUNNING"),
ACTIVITY_4(4, "STRENGTH"),
ACTIVITY_5(5, "WALKING");
private final String activityName;
private int activityNumber;
private ActivitiesModeEnum(final int activityNumber, final String activityName) {
this.activityNumber = activityNumber;
this.activityName = activityName;
}
public String getActivityName() {
return activityName;
}
public int getActivityNumber() {
return activityNumber;
}
public static ActivitiesModeEnum valueOfActivity(final int activityNumber) {
final ActivitiesModeEnum[] values = ActivitiesModeEnum.values();
for (final ActivitiesModeEnum activityModeEnum : values) {
if (activityModeEnum.getActivityNumber() == activityNumber)
return activityModeEnum;
}
return ACTIVITY_0;
}
public static List<ActivitiesModeEnum> getAll() {
final List<ActivitiesModeEnum> valuesList = new ArrayList<ActivitiesModeEnum>();
final ActivitiesModeEnum[] values = ActivitiesModeEnum.values();
for (final ActivitiesModeEnum activityModeEnum : values) {
valuesList.add(activityModeEnum);
}
return valuesList;
}
}
and I want to retain the selected item from my spinner in a variable called, activityType, in function of my enum, could someone please give me some clues how could i do it?
I'm trying to sort a list of objects in java using Collections.sort(). But I keep getting this error: type parameter is not within its bound". Does anyone know how I can remedy this problem?
My code
public List<String> fetchNumbersForLeastContacted()
{
List<String> phonenumberList = getUniquePhonenumbers();
List<TopTen> SortList = new ArrayList<TopTen>();
Date now = new Date();
Long milliSeconds = now.getTime();
//Find phone numbers for least contacted
for (String phonenumber : phonenumberList)
{
int outgoingSMS = fetchSMSLogsForPersonToDate(phonenumber, milliSeconds).getOutgoing();
int outgoingCall = fetchCallLogsForPersonToDate(phonenumber, milliSeconds).getOutgoing();
//Calculating the total communication for each phone number
int totalCommunication = outgoingCall + outgoingSMS;
android.util.Log.i("Datamodel", Integer.toString(totalCommunication));
SortList.add(new TopTen(phonenumber, totalCommunication, 0));
}
//This is where I get the error
Collections.sort(SortList);
The TopTen.class
public class TopTen {
private String phonenumber;
private int outgoing;
private int incoming;
public TopTen (String phonenumber, int outgoing, int incoming)
{
this.phonenumber = phonenumber;
this.incoming = incoming;
this.outgoing = outgoing;
}
public String getPhonenumber() {
return phonenumber;
}
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
}
public int getOutgoing() {
return outgoing;
}
public void setOutgoing(int outgoing) {
this.outgoing = outgoing;
}
public int getIncoming() {
return incoming;
}
public void setIncoming(int incoming) {
this.incoming = incoming;
}}
public static void sort (List<T> list)
This method can only be used if T inplements the Comparable interface. What implements Comparable means is that there exists a criteria by which two objects of type T can be compared and ordered. In your case, T is TopTen, which does not implement Comparable.
What you need to do:
public class TopTen implements Comparator<TopTen> {
....
....
#Override
public int compareTo(TopTen other) {
if (this == other) return EQUAL;
return this.getPhonenumber().compareToIgnoreCase(other.getPhonenumber());
}
This will compare two TopTen objects based on the phonenumber field. If you want the objects to be ordered based on another criteria, use that to return either -1 (before), 0 (equal) or 1 (after).
For example, to base the sorting on incoming, use the following:
#Override
public int compareTo(TopTen other) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this == other) return 0;
if (this.getIncoming() > other.getIncoming()) {
return AFTER;
} else if (this.getIncoming() < other.getIncoming()) {
return BEFORE;
} else {
return EQUAL;
}
}
This would get you TopTen objects ordered by ascending incoming field values.
try implementing Comparable interface in TopTen class and override compareTo method to specify your sorting logic
#Override
public int compareTo(TopTen o) {
// TODO Auto-generated method stub
return 0;
}
(or)
Collections.sort(SortList, new Comparator<TopTen>(){
public int compare(TopTen t1, TopTen t2) {
return t1.phonenumber.compareTo(t2.phonenumber);
}
});
I trying to pass array of objects via Parcelable. But after the transfer, the data is converted into something strange
The transmitting part:
for (int i=0; i<res.size(); i++) {
Log.d(LOG_TAG, "id = "+res.get(i).id+" weigth = "+res.get(i).weight);
}
ParcelableProducts Checked = new ParcelableProducts();
Checked.setList(res);
intent.putExtra(ParcelableProducts.class.getCanonicalName(), Checked);
The receiving part:
ParcelableProducts res = (ParcelableProducts) data.getParcelableExtra(ParcelableProducts.class.getCanonicalName());
ArrayList<prProduct> prod = res.prod;
for (int i=0; i<prod.size(); i++) {
Log.d(LOG_TAG, "id = "+prod.get(i).id+" weigth = "+prod.get(i).weight);
}
Classes
Parcelable with ArrayList:
public class ParcelableProducts implements Parcelable {
final private static String LOG_TAG = "ParcelableProducts";
public ArrayList<prProduct> prod;
public ParcelableProducts() {
prod = new ArrayList<prProduct>();
}
public void setList(ArrayList<prProduct> _prod){
prod = _prod;
}
public ArrayList<prProduct> getList() {
return prod;
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeList(prod);
}
public static final Parcelable.Creator<ParcelableProducts> CREATOR = new Parcelable.Creator<ParcelableProducts>() {
public ParcelableProducts createFromParcel(Parcel in) {
return new ParcelableProducts(in);
}
public ParcelableProducts[] newArray(int size) {
return new ParcelableProducts[size];
}
};
private ParcelableProducts(Parcel parcel) {
prod = new ArrayList<prProduct>();
parcel.readTypedList(prod, prProduct.CREATOR);
}
}
and prProduct:
public class prProduct implements Parcelable {
final static String LOG_TAG = "prProduct";
public float weight;
public int id;
public prProduct(int _id, Float _weight) {
weight = _weight;
id = _id;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeFloat(weight);
parcel.writeInt(id);
}
public static final Parcelable.Creator<prProduct> CREATOR = new Parcelable.Creator<prProduct>() {
public prProduct createFromParcel(Parcel in) {
return new prProduct(in);
}
public prProduct[] newArray(int size) {
return new prProduct[size];
}
};
private prProduct(Parcel parcel) {
weight = parcel.readFloat();
id = parcel.readInt();
}
}
in log:
Transmit: id = 7 weigth = 0.0
Recive: id = 7602278 weigth = 4.2E-44
Off hand I don't see where the data is getting corrupted in transmission, but it will help to clean up your code. Personally I have fixed many weird bugs in the past when I refactor my code to improve readability. First thing you should do is remove the class "ParcelableProducts" because you don't need it. Just pass the ArrayList in the intent directly using the putParcelableArrayListExtra method. Shown here.
Also this is a bit nit picky but you shouldn't directly access your fields. It is better to set them as private and use getters/setters. Also using a for each loop for your logging statement would be a bit cleaner.
A safer PrProduct class.
//Java classes should start with capital letter
public class PrProduct implements Parcelable {
private final static String LOG_TAG = "PrProduct";
private float weight;
private int id;
public prProduct(int id, float weight) {
this.weight = weight;
this.id = id;
}
//Using getters only makes this immutable which is safer since the
//weight/id aren't likely to change.
public float getWeight(){
return weight;}
public int getId(){
return id;}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeFloat(weight);
parcel.writeInt(id);
}
public static final Parcelable.Creator<prProduct> CREATOR = new
Parcelable.Creator<prProduct>() {
public prProduct createFromParcel(Parcel in) {
return new prProduct(in);
}
public prProduct[] newArray(int size) {
return new prProduct[size];
}
};
private prProduct(Parcel parcel) {
weight = parcel.readFloat();
id = parcel.readInt();
}
}
//A sample for each loop
for(PrProduct product: prod)
Log.d(LOG_TAG, "weight=" + product.getWeight() + " id=" + product.getId());
Why do you need to create the object ParcelableProducts that implements Parcelable? I think you can just pass the arraylist directly using putParcelableArrayListExtra method from the intent?