-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Entities implementing Parcelable #4
Comments
+1 for this, would be awesome |
I am actually exactly at the point where I would prefer to just pass the entity to another intent. Right now I am passing always the entity id and doing a query in the new Activity again. I guess that the DAO is doing some caching, thus this query should be quite quick. I heard that Serialization in Android is not very fast. So what is finally the best way to do it? |
@deradam: passing IDs is fine. greenDAO's load() tries to do a map lookup with the ID first (identity scope), so this should be very, very fast if the entity is available. This should be even faster than creating the parcel and making an object out of it again. One thing to keep in mind: The identity scope holds only weak references to the entity, but usually the entities are referenced in the calling activity. |
Any news about this feature? |
I too would get great use out of this feature. I want to eliminate a DB hit when the device is rotated and my Fragment is recreated to improve latency. Since all the fields and types are declared, it seems it would be possible... |
This feature would certainly improve the generation process. |
Any news about this feature, is it even in consideration? At least I'd like to be able to remove the "private" modifier so I can implement @parcel, but until then - poor serialization.... |
Hello no news about parcelable? |
You can add Parcelable support right now by using interfaces and keep sections. The downside is that the Parcelable code is not updated when the entity fields change, although the Parcelable code will be retained when you generate the entire schema again. I would be interested in better parcelable support that automatically updates the parcelable code when the entity fields change. Here is how to manually add Parcelable support:
Find the KEEP INCLUDES section and move all the custom imports there:
HINT: You can use a plugin that automatically writes the Parcelable boilerplate.
|
I have modified our local branch to partially support this. It makes sense with dynamic to not have to use the KEEP blocks. |
in my case i add this to parcelable methode so we prevent the detached from DAO exception when you passe an object to a new Activity protected Entity (Parcel in) { |
How to do it with greedDao gradle plugin?
|
@adjorno See my comment on #427 for an example. -ut |
Thanks, but I have just realized that its illegal to make greeanDao entities Parcelable: I see 2 solutions:
Is there any ways to save & restore greenDao entities? |
@adjorno Simple answer: don't. Just query for them again. greenDAO will hold onto entity instances in its session cache, so on config changes a query returns the same objects without having to re-create them. Edit: Or use the Android Loader framework or something equivalent. -ut |
I guess the caching doesn't work for my case, because I query raw sqlite request: SELECT TRACK_ID, ARTIST_ID, TRACK.TITLE, ARTIST_ID, ARTIST.NAME, ... I do it via raw request since I could not find any support of aggregate functions (SUM) and grouping (GROUP BY) in greenDao. On some slow devices it takes up to 10 seconds to handle this request (~200K tracks) and I don't want to do it again on config changes. I'd like to have a possibility to get these entities fast that is why I wanted to put them into the Bundle. Now I see that it is illegal with greenDao. |
As said, this is exactly what the Android loader framework is for. Just write your own AsyncTaskLoader. -ut |
Annoying boiler plate code is just perfect for geenDAO...
The text was updated successfully, but these errors were encountered: