언어 설정

Menu
Sites
Language
localStorage items are not modified by setItem()

Hi.

I'm facing a strage localStorage behavior. After setting some data with setItem() first time, it stays the same every time I try to modify it.

So I'm setting up some options\settings: setItem('a', 'a')

Then during app launch:

1) getItem('a') -> 'a'

2) setItem('a', 'b')

3) getItem('a') -> 'b'

BUT if i kill the app with Task Switcher and restart it getItem('a') gives me 'a' again! Any ideas on this issue?

Edited by: Brock Boland on 17 3월, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

22 댓글
Lakshmi Grandhi
Hi, Its strange, i tested it on emulator its working fine. On which SDK are you setting?? localStorage.setItem('favoriteflavor','vanilla'); $("#bt1").click(function(){ console.log(localStorage.getItem('favoriteflavor') ); localStorage.setItem('favoriteflavor', 'vanilla1' ) ; }); $("#bt2").click(function(){ console.log( localStorage.getItem('favoriteflavor') ); });
Dmitry Utkin
Hi, i'm using a dev device PQ with 2.1 Everything works fine on web simulator, cause it's Chrome basically :) localStorage works OK during one launch of the app, but once it's killed and relaunched - old\initial state of localStorage pops up. Have you tried that case?
Lakshmi Grandhi
Hi, you can use local storage using config preference add item "a" set value "a" , in code can set and set values. var value = widget.preferences.getItem("a"); widget.preferences.setItem("a", "b"); it will retain using even after relaunch
Lakshmi Grandhi
Hi, you can use local storage using config preference add item "a" set value "a" , in code can set and set values. var value = widget.preferences.getItem("a"); widget.preferences.setItem("a", "b"); it will retain using even after relaunch
Dmitry Utkin
console.log('favoriteflavor is ' + widget.preferences.getItem('favoriteflavor')); widget.preferences.setItem('favoriteflavor', 'vanilla1'); console.log('favoriteflavor is ' + widget.preferences.getItem('favoriteflavor')); gives me this in logs D/ConsoleMessage(19256): file:///opt/usr/apps/Jll4ZF053P/res/wgt/js/main.js:674:favoriteflavor is null E/ConsoleMessage(19256): file:///opt/usr/apps/Jll4ZF053P/res/wgt/js/main.js:675:[object DOMException] But what about standard localStorage? Is it just me or there's a bug?
Marco Buettner
I can not reproduce this issue. I use also localStorage and it works without any problems. But maybe it helps if you delete the old value with "localStorage.removeItem('a');" before you use setItem again. But normally it should works without any problems.
Dmitry Utkin
Tried that too, nothing changes. Looks like localStorage being saved at first launch and then it's state restored each time.
Marco Buettner
It doen't. localStorage works perfect. I used in my app to save and change the optic of elements. After terminating and restart the last saved colors will used!
function save(value, key)
{
    localStorage.setItem(key, value);
}

function load(key)
{
    response = localStorage.getItem(key);
    return response;
} 

function saveSettings()
{
    //Text Values
    var fontstyle = document.selectForm.fontStyle.value;
    var fontweight = document.selectForm.fontWeight.value;
    var fontcolor = document.selectForm.fontcolor.value;
    var fontopacity = document.selectForm.fontopacity.value;
  
    var alignment = document.selectForm.alignment.value;
    // Border Values
    var borderstyle = document.selectForm.borderstyle.value;
    var bordersize = document.selectForm.bordersize.value;
    var bordercolor = document.selectForm.bordercolor.value;
    var borderradiusTopLeft = document.selectForm.borderradiusTopLeft.value;
    var borderradiusTopRight = document.selectForm.borderradiusTopRight.value;
    var borderradiusBottomLeft = document.selectForm.borderradiusBottomLeft.value;
    var borderradiusBottomRight = document.selectForm.borderradiusBottomRight.value;
    var opacity = document.selectForm.opacity.value;
    // Background Values
    var backgroundcolor = document.selectForm.backgroundcolor.value;
    // Date Values
    var datemode = document.selectForm.datemode.value;
    var yearMode = document.selectForm.yearMode.value;
    var shortMode = document.selectForm.shortMode.value;
    // Effect Values
    var glasses = document.selectForm.glasses.value;
    var glow = document.selectForm.glow.value;
    var glowColor = document.selectForm.glowColor.value;
  
    if(fontcolor == backgroundcolor)
        alert(GetMessage("ErrorColor"));
    else
    {  
        // Text Values
        save(fontstyle, "fontStyle");
        save(fontweight, "fontWeight");
        save(fontcolor, "fontcolor");
        save(fontopacity, "fontopacity");
        save(alignment, "alignment");
        // Border Values
        save(borderstyle, "borderstyle");
        save(bordersize, "bordersize");
        save(bordercolor, "bordercolor");
        save(borderradiusTopLeft, "borderradiusTopLeft");
        save(borderradiusTopRight, "borderradiusTopRight");
        save(borderradiusBottomLeft, "borderradiusBottomLeft");
        save(borderradiusBottomRight, "borderradiusBottomRight");
        // Background Values
        save(backgroundcolor, "backgroundcolor");
        save(opacity, "opacity");       
        // Date Values
        save(datemode, "datemode");
        save(yearMode, "yearMode");
        save(shortMode, "shortMode");
        // Effect Values
        save(glasses, "glasses");
        save(glow, "glow");
        save(glowColor, "glowColor");
  
        closeSettings();
    }
}

function loadSettings()
{
    if(localStorage.length == 0)
        saveSettings();
    // Text Values
    document.selectForm.fontStyle.value = load("fontStyle");
    document.selectForm.fontWeight.value = load("fontWeight");
    document.selectForm.fontcolor.value = load("fontcolor");
    document.selectForm.fontopacity.value = load("fontopacity");
    document.selectForm.opacity.value = load("opacity");
    document.selectForm.alignment.value = load("alignment");
    // Border Values
    document.selectForm.borderstyle.value = load("borderstyle");
    document.selectForm.bordersize.value = load("bordersize");
    document.selectForm.bordercolor.value = load("bordercolor");
    document.selectForm.borderradiusTopLeft.value = load("borderradiusTopLeft");
    document.selectForm.borderradiusTopRight.value = load("borderradiusTopRight");
    document.selectForm.borderradiusBottomLeft.value = load("borderradiusBottomLeft");
    document.selectForm.borderradiusBottomRight.value = load("borderradiusBottomRight");
    // Background Values
    document.selectForm.backgroundcolor.value = load("backgroundcolor");
    // Date Values
    document.selectForm.datemode.value = load("datemode");
    document.selectForm.yearMode.value = load("yearMode");
    document.selectForm.shortMode.value = load("shortMode");
    // Effect Values
    document.selectForm.glasses.value = load("glasses");
    document.selectForm.glow.value = load("glow");
    document.selectForm.glowColor.value = load("glowColor");
  
    if(localStorage.length != 0)
        saveSettings();
}

function appInit()
{
    show();
    $("#clockbox").show();
    $("#settingbox").hide();
    loadSettings();
}
  
$(document).ready(appInit);
And it works perfect! Everytime and every situation. While app runs or after restart
Dmitry Utkin
Are you using an emulator, web simulator or a test device?
Marco Buettner
it works on all three environments!
Dmitry Utkin
Can you show me the closeSettings() function mentioned in your code, maybe there's some magic that I'm not aware of...
Marco Buettner
I dont think so ;)
function closeSettings()
{
	$("#clockbox").show();
	$("#settingbox").hide();
}
Dmitry Utkin
:D
Marco Buettner
I hope it will be better if you show your original code snippet not as "pseudo"-code or code issue.
Marco Buettner
I hope it will be better if you show your original code snippet not as "pseudo"-code or code issue.
Dmitry Utkin
It's not the code, I found the root of the issue https://developer.tizen.org/forums/web-application-development/localstorage-items-are-not-modified-setitem#comment-3319
Dmitry Utkin
I was running out of ideas, but then I've noticed this messages in dlog E/Tizen::Io( 2609): static bool Tizen::Io::File::IsFileExist(const Tizen::Base::String&)(300) > [E_INVALID_ARG] Given filePath length is zero or exceeds system limitations. E/Tizen::App( 2609): Tizen::Base::Collection::ArrayList* Tizen::App::Package::_PackageManagerImpl::GetPackageAppFeatureListN(const Tizen::App::PackageId&, const Tizen::Base::String&) const(1882) > [E_OUT_OF_MEMORY] AppInfo list instance must not be null. E/Tizen::App( 2609): static Tizen::Base::String Tizen::App::_ContextManager::_Util::QueryFeatureFromPackageManager(const Tizen::Base::String&, const Tizen::Base::String&, const Tizen::Base::String&)(492) > Cannot acquire feature list. E/Tizen::App( 2609): void Tizen::App::_ConditionManagerStub::OnInstallComplete(const Tizen::App::AppId&)(132) > failed to GetAppLaunchConditionListN(Jll4ZF053P.implus) and I've tried to change the app name by replacing "+" to "plus". And now localStorage works as it should! I don't know if it's a known issue or 'undefined behavior', but I thinks it's easy to support symbols except a-zA-Z0-9.
Dmitry Utkin
Heh... seems like I was wrong about the cause. localStorage doesn't update again :(
Marco Buettner
Publish your code or if you not trust you can send me an email on support@scidev.eu - I will check your code and test it also and maybe I found a solution for your problem. I use localStorage since Tizen 1.0 without any problems on ALL my apps.
Dmitry Utkin
2.2 Beta fixes this so far I can see. Hope this is solved now.
Marco Buettner
It will be nice if it solved... But it should work always since Tizen 1.0 :) Maybe your Tizen 2.1 Flash wasn't complete successful or something like that. And dont forget if you reinstall your application via SDK user data (localStorage) will be also clean because the application will be completly uninstall before it installed again.
Dmitry Utkin
Not if you enable 'update mode' with disabled RDS :)