realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Best practice for session data

Open petersnoopy opened this issue 11 years ago • 3 comments

Hi,

I need some tipps/suggestion/ideas about how to use Realm in combination with session data. The user can edit data which are loaded from Realm. The changes the user has just made should be recovered after a configuration change of the device and only stored when he clicks on the save/done button.

Currently i copy all from the Realm objects to parcelable objects with the same structure. Changes are only be done on the parcelable objects. When a config change happens the session data is passed as argument to the onSaveInstanceState method....

I would like to avoid copying from and to Realm objects and the usage of disposable (parceable) objects. So what would be the best strategy to these kind of session data?

petersnoopy avatar Feb 19 '15 13:02 petersnoopy

If you don't want to copy data to another object there is a few scenarios you can use:

  1. Save the RealmObject in a static variable instead of a Bundle
  2. Save the RealmObject inside Realm with a added tmp or unsaved boolean which you can check.

Neither is perfect, but we are currently evaluating how to best support Parcelable, so hopefully we can soon provide a solution.

cmelchior avatar Feb 19 '15 20:02 cmelchior

Hi @petersnoopy I assume you got your question answered. Feel free to add additional information if this is not the case.

cmelchior avatar Feb 24 '15 14:02 cmelchior

Hi @cmelchior I have a related question: I would like to save also RealmObjects (to be more specific some RealmResults) to the instance state, in case the app is killed by the OS and when user opens it again, then I would like to recover the RealmResults object(s). What would be the best way to do it? Could you give some advice?

gergokajtar avatar Mar 31 '15 16:03 gergokajtar