Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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... [2]: http://developer.android.com/training/basics/activity-lifecy...



I use Parceler (https://github.com/johncarl81/parceler) with gson. So gson for network data, then parceler for passing parcels around between activities/fragments.


Doesn't this require annotating the class? What if I can't change the class implementation?


One 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.


The 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.


You 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: