Hybrid View
-
10 Apr 2012 1:12 AM #1
Answered: Best practices to save user settings locally
Answered: Best practices to save user settings locally
Hello!
Are there best practices when storing user settings locally in Sencha Touch? Example:
A simple, one user, app where the user can change some settings - like background color, text size etcetera.
Use case:- The user navigates to the settings view
- The user changes some settings in an ordinary form
- The user clicks save and the settings are persisted
Thanks!
-
Best Answer Posted by mrsunshine
you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one
-
10 Apr 2012 1:13 AM #2Sencha - Training Team
- Join Date
- Sep 2008
- Location
- Germany - Darmstadt
- Posts
- 682
- Vote Rating
- 10
- Answers
- 21
yes, the easiest way is to create a settings model and store it in the localstorage
trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
10 Apr 2012 1:22 AM #3
How do I make sure that theres only one settings object persisted?
-
10 Apr 2012 1:27 AM #4Sencha - Training Team
- Join Date
- Sep 2008
- Location
- Germany - Darmstadt
- Posts
- 682
- Vote Rating
- 10
- Answers
- 21
you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one
trainings / workshops / consulting: Sencha Touch / Ext JS
Profile on SenchaDevs
www: http://www.nils-dehl.de
twitter: nilsdehl
meetup: Sencha Touch / Ext JS Meetup Frankfurt
videos: http://vimeo.com/album/1621422
conference photos: http://www.flickr.com/photos/nils-dehl/
-
10 Apr 2012 1:33 AM #5
Before you put too much effort into using localstorage you should read this:
http://www.softwareindustryinsights.com/2012/04/building-hybrid-apps-important-change-in-ios-5-1/
Basically what it means is that the localstorage for WebViews (like phonegap and sencha) is now treated as a temporary store that can be cleared at any time by the OS. So do not trust it to remain after you application is closed.
-
14 Apr 2012 11:55 PM #6
-
10 Apr 2012 1:38 AM #7
Ok, the manual way then.
I thought that maybe there is a function to save user settings through the framework. But now I now it doesn't. Thank you!
-
19 Jun 2012 7:43 AM #8
I'm doing this, but notice that if I check the Resources tab in Chrome's Developer Tools under LocalStorage -> localhost, I can see that there are entries for both 'myUniqueProxy' and 'myUniqueProxy-0' (I set the id to the model to be 0).
There are never any more entries in 'myUniqueProxy-0' other than the one I want, however it looks like there are tons entries for '0' in 'myUniquProxy'. Apparently one for every save despite it being the same record.
Here's an image of what I'm seeing (don't pay attention to any malformed data, I modified it for this post):
screenshot.png
My proxy is setup like this:
My Model has an id field like this:Code:proxy : { type : 'localstorage', id : 'myUniqueProxy', }
Then just like you said, I call for the store to getRecordById(0), update that record with current data and save it.Code:{ name : 'id', type : 'integer', defaultValue : 0, isUnique : true }
Am I doing something wrong to get so many entries in the 'myUniqueProxy' entry?
Thanks in advance for any advice.
bwagsLast edited by bwags; 19 Jun 2012 at 7:48 AM. Reason: Added image
-
3 Jul 2012 12:57 AM #9
Hi there,
I was wondering if you happened to find a workaround for this? When you reload the page do you automatically get more entries in local storage. There should only be one entry in localstorage which we update, but it appears to create new objects upon refresh.
Thanks. :-)


Reply With Quote