window.localStorage data is cleared after app re-installation via Tizen Studio

Original Created Jan 10, 2020 | Regeneration Apr 22, 2026

I'm developing a Tizen web application where I use JavaScript's localStorage to store and retrieve data. However, I've noticed that whenever I reinstall my application through Tizen Studio, all localStorage data gets cleared.

Is there an alternative data storage method that will persist even after application reinstallation?

Problem Understanding

The issue occurs because localStorage is designed to be cleared when an application is uninstalled. This is standard behavior across platforms. When you reinstall your application through Tizen Studio, it performs a complete uninstall/reinstall cycle, which clears the localStorage.

Solution Methods

  1. Use Tizen Filesystem API: The tizen.filesystem API provides persistent storage that survives application reinstallation.
  2. Implement a localStorage-like wrapper: Create a custom storage solution that uses the filesystem API but mimics localStorage's interface.
  3. Enable Rapid Development System: This feature in Tizen Studio replaces only changed files during development, avoiding complete reinstallation.

Code Examples

Here's a complete implementation of a localStorage-like wrapper using tizen.filesystem:

// tizen-storage.js
/**
 * Default storage directory on Tizen file system
 */
const storageDir = 'documents';

/**
 * Uses the tizen.filesystem API to store and get data
 */
export default {
  set: (key, value, dir = storageDir) => {
    if (!window.tizen || !window.tizen.filesystem) {
      localStorage.setItem(key, value);
      return;
    }
    const handle = window.tizen.filesystem.openFile(`${dir}/${key}`, 'w');
    handle.writeString(value);
    handle.close();
  },

  get: (key, dir = storageDir) => {
    if (!window.tizen || !window.tizen.filesystem) {
      return localStorage.getItem(key);
    }
    let handle;
    let content;
    try {
      handle = window.tizen.filesystem.openFile(`${dir}/${key}`, 'r');
    } catch (err) {
      return null;
    }
    content = handle.readString();
    handle.close();
    return content;
  }
}

Example usage:

import tizenStorage from './tizen-storage';

export const updateHasPlayed = (url, currentTime) => dispatch => {
  const key = 'hasPlayed';
  const currentHasPlayed = tizenStorage.get(key);
  const json = currentHasPlayed === null
    ? {}
    : JSON.parse(currentHasPlayed);

  json[url] = currentTime;
  tizenStorage.set(key, JSON.stringify(json));
}

Additional Tips

  • The filesystem API requires appropriate privileges in your config.xml:
    <tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>
    <tizen:privilege name="http://tizen.org/privilege/filesystem.write"/>
    
  • For development purposes, consider enabling Rapid Development System in Tizen Studio to avoid frequent data loss during testing.
  • Remember that filesystem operations are asynchronous in nature, so consider error handling for production applications.

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.