GithubHelp home page GithubHelp logo

awadalaa / android-global-parcelable Goto Github PK

View Code? Open in Web Editor NEW
20.0 20.0 12.0 620 KB

Serialization in Java was far too slow for Android, so they created the Parcelable class that android developers use to serialize data. The Parcelable approach requires that you explicitly serialize the members of your class, but in the end, you get a much faster serialization of your objects. The problem is you have to do this with every class you create. In a large project with many classes with many objects this becomes tedious violating the rules of code reusability. The solution is to create the Global Parcelable class that all other classes can extend.

Java 100.00%

android-global-parcelable's People

Contributors

awadalaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-global-parcelable's Issues

Library uses reflection

This library uses reflection to parcel the objects. What's the difference between that and Serializable?
Serializable uses reflection, which is why it is slow. Parcelable is faster because the boiler-plate code removes the need for reflection.

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

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.