MA4: App architecture, state and storage on the phone

Lesson 3 of 5 · reading 15–25 minutes; practice and project time is on the module page

Storing data on the phone

🎯You'll be able to

Choose between key-value storage, SQLite, secure storage and files, and decide what shouldn't be stored at all.

🏠The everyday picture

At home you keep spices in a rack, documents in a locked drawer, photos in albums and the week's menu on the fridge. Each place suits what goes in it.

📘What it really is

📝A worked example

Input: KhetNote must keep visits, the outbox and the sync cursor between launches.

Steps:

  1. For a few thousand records, key-value storage is enough: one JSON object under khetnote:v1.
  2. Write after each change, in order, so a later write can't be overtaken by an earlier one.
  3. Note when to move to SQLite: tens of thousands of visits, or searching on the phone.

Expected output: a storage choice with a reason and a point at which you'd change it.

🌍Where it's used

📝Case scenario

A delivery app kept a sign-in token in plain key-value storage. On a rooted test phone, a security review read it in a minute. Moving it to secure storage, and keeping only non-secret data in the plain store, closed the finding.

🖱️Try it

Read the starter's src/storage/store.js and write one sentence on why its data disappears when the app restarts. Success: you name the line where the data is kept.

⚠️Common mistakes

🛠️For your project

Project 1's test 1 creates a store, saves a visit, then creates a new store with the same storage and checks the visit is still there.

✅Quick check

Where should a sign-in token be stored on a phone?

Show the answer

In secure storage (the Keychain or Keystore), not in plain key-value storage.

When would you move from key-value storage to SQLite?

Show the answer

When there are many records, or the app needs to search or update parts of the data.

← PreviousWhere state lives
ProLearners Assist