Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not sure this works for inherited classes that are stored in arrays #1

Open
deragun opened this issue Dec 24, 2013 · 1 comment
Open

Comments

@deragun
Copy link

deragun commented Dec 24, 2013

I love this idea, and I may be missing something obvious, but I'm not certain this works if you have arrays of inherited classes that need to be parceled. Here's the setup I'm trying:

public class Instruction extends GlobalParcelable {
    protected intID;
    protected intOrdinal;
    protected strDescription;

    public Instruction(Integer id, Integer ordinal, String description) {
        this.intID = id;
        this.intOrdinal = ordinal;
        this.strDescription = description;
    }
    //also has getters/setters
}


public class Setup extends Instruction {
    public Setup(Integer id, Integer ordinal, String description) {
        super(id, ordinal, description);
    }
}


public class Step extends Instruction {
    public Step(Integer id, Integer ordinal, String description) {
        super(id, ordinal, description);
    }
}

In my app, all of this rolls up into a Recipe object that has:

public class Recipe extends GlobalParcelable {
    ...
    private ArrayList<Step> steps;
    private ArrayList<Setup> setups;
    ...
}

It's the Recipe object that gets passed around from Activity to Activity.

Do I need to put the Creator interface in each class even though I'm extending GlobalParcelable? Or is there a different way I should be trying to utilize GlobalParcelable in this type of case? I'm thinking the core of the issue is that it seems as though dehydrate/rehydrate only deal with basic data types and don't specifically handle Fields that are arrays of parcelable objects.

Also, side note while I'm doing some poking around to try to better understand this, would there be an issue with the Inheritance structure used above due to getDeclaredFields()? A Step has no defined fields other than those inherited from Instruction, and from the docs it seems getDeclaredFields doesn't include inherited fields. So would having GlobalParcelable use getFields() instead be a better approach in this case?

Thanks.

@rdenadai
Copy link

@deragun don't know if you find a solution to this, but im also using this class, and as i notice your classes that will be put on the arraylist must also extends GlobalParcelable.
Doing that is working good to me... now im facing another problem... since my app is being destroyed after some time, when i reopen the app, the Parcelable classes are being destryoed and i must create an empty constructor to reinitiante then (which in my case is bad). Im going to try using a constructor with a Parcel value and use the default constructor of GlobalParcelable to do the jobs... im with fingers crossed here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants