3 ms·
I've always wondered how folks handle the Parcelable[1] interface with libraries like this. If you have a realm object that you want to have in memory between a
by zackb 12y ago
I've always wondered how folks handle the Parcelable[1] interface with libraries like this. If you have a realm object that you want to have in memory between activity destroy/create how do you handle this? For instance if I rotate the screen the activity is destroyed and recreated for the new orientation. As I understand it the Parcelable interface and Bundle[2] is the way to handle this but how can you do this if you're using third party classes/objects?
Thanks!
[1]: http://developer.android.com/reference/android/os/Parcelable.html http://developer.android.com/reference/android/os/Parcelable...
[2]: http://developer.android.com/training/basics/activity-lifecycle/recreating.html http://developer.android.com/training/basics/activity-lifecy...
- emanuelez 12y agoThe main difference is that with Parcelable you have two versions of your object (one persisted on disk and one in memory) while with Realm you are always working with your real data, not a representation of it.
- makeramen 12y agoI use Parceler (https://github.com/johncarl81/parceler https://github.com/johncarl81/parceler) with gson. So gson for network data, then parceler for passing parcels around between activities/fragments.
- zackb 12y agoDoesn't this require annotating the class? What if I can't change the class implementation?
- johncarl81 12y agoOne way to use Parceler is to annotate the class. There are a lot of other options though, including configuring the class outside of the class using @ParcelClass (useful for libraries) or writing a ParcelConverter.
- swanson 12y agoYou can always just put the model id (or some other way to requery) in the Bundle and look it up again after the configuration change.