← Data apps

Saving between visits

Make the playlist remember its songs when the app is closed and opened again: tick Remember between visits on the Songs table, test a return visit and a first visit, and greet the user differently on each. The songs are kept in this browser only.

Close a notes app and open it tomorrow: your notes are still there. An app that forgets everything when it closes isn't much use for keeping a list.

So far, every time the app starts, the table goes back to the rows you typed in the sidebar. Today the playlist will remember what was added, so a song added today is still there tomorrow.

The playlist app with a line saying "Welcome back. Songs saved: 3" above the table of songs.

How this lesson works: See it, Build, Check, Make it yours
See itTry the finished thing first, so you know what you are building.

Try the finished app

This is the app you'll build, open on the Run tab. Add a song, then press ↻ Restart: the app starts again, and your song is still there. Now press Forget saved data: it's like opening the app for the first time.

Try it yourselfYour edits are saved in this browser.

BuildWatch the short clip, then do the steps. Your app carries on from the step before.

Build 1: remember the songs

  1. On the left, under Tables, find Songs and click its 💾 button. It lights up: Songs is now remembered.
  2. Open the Run tab. Add two songs.
  3. Press ↻ Restart. Are your songs still there?
  4. Press Forget saved data. The table goes back to its one starting song.
Remember between visits · Sound on for the voiceover
Try it yourselfYour edits are saved in this browser.

The Songs table is remembered between visits.

    Run your program. This ticks when your code does all of the above.

    BuildWatch the short clip, then do the steps. Your app carries on from the step before.

    Build 2: first visit or return visit?

    1. Add an event: Screen, On start of screen. Leave it with no actions.
    2. Give it a sub-event with the condition Compare count(Songs) = 0, and the action Set WelcomeText text to "Add your first song".
    3. Add an Else below the sub-event (its ⋯ menu), with Set WelcomeText text to "Welcome back. Songs saved: " & count(Songs).
    4. Test both visits: Restart with songs saved, then remove every song and Restart again.
    Try it yourselfYour edits are saved in this browser.

    When the screen starts: with no songs, WelcomeText says to add the first one; otherwise it welcomes the user back with the number of songs.

      Run your program. This ticks when your code does all of the above.

      CheckA quick check that the idea has stuck.

      Check: where is it kept?

      Kai's playlist remembers Songs. Kai adds five songs at home, then opens the same app on a school computer. What does the table show?

      Kai presses Save at the top and hands in the project file. Which songs are in it?

      Make it yoursChange your app on purpose, then try it on someone.

      Make it yours: remember the last song

      There's a variable LastAdded.

      1. Click its 💾 so it's remembered too.
      2. In the AddButton event, add Set variable LastAdded to TitleInput.text.
      3. Add it to the welcome back message, such as & ". Last added: " & LastAdded.

      Anyone who uses this browser next will see what the app remembered. Write down one thing a user should know about that, and where in your app you'd tell them.

      Try it yourselfYour edits are saved in this browser.

      A remembered variable LastAdded is set to the new title when a song is added, and the welcome back message shows it.

        Run your program. This ticks when your code does all of the above.

        Now you can
        Next lesson5. A journal with drawingsGive every journal entry its own drawing: a table Entries with a picture field, a row added for each entry, a Table on the Journal screen with a thumbnail per row, and a click to see one big. Remember it between visits, tidy away the old list, and hand it in as a file with the drawings inside.
        For teachers

        Students make the playlist remember its songs between visits with App Builder's Remember toggle (💾) on the Songs table, test return visits with Restart and first visits with Forget saved data, and greet the user differently on each with count(Songs) in an On start of screen event with Else. The Check separates what the browser keeps from the project file and from other computers. About 45 minutes.

        Open the teacher guide: answers, solutions, slides and a worksheet.

        Students will be able to

        Before class

        Remember between visits keeps values in the browser's local storage, under this lesson step's own key: on this computer, for this browser user. Nothing is sent anywhere, and nothing goes into the project file (Save keeps the starting rows).

        On shared computers, the next person in the same browser sees what was remembered. Keep data made up, and talk about it: it's a real design question for any app.

        Running the lesson

        1. Before Build 1 (whole class): which apps remember things between visits? Where do you think they keep it?
        2. Build 2: test both visits before moving on: Restart with songs, then Forget saved data.
        3. Check: the Kai question is worth a minute's discussion: who else could see a saved journal?

        The hard part (on purpose)

        Testing: students expect to close the page. Restart (a return visit) and Forget saved data (a first visit) test both without waiting.

        When students get stuck

        Stretch and support

        Stretch: Remember how many times the app has been opened: a remembered variable that goes up by 1 on start of screen.

        Support: Demonstrate a return visit and a first visit on the projector before students build.

        Where it leads

        Next: Search, filter and sort.

        What each step is for