Storing Data in App Inventor

  • Learn how to store data on a mobile device to access from a mobile app
  • Learn of different options for storing and accessing data in the cloud to share data between app users

These are the activities for this lesson:

STORING LONG TERM DATA

In the last unit, you learned how to use variables and lists to store information in your app. 

When the app is closed, all variables stored in the app’s memory are wiped away. 

There are times, though that you might want keep track of information between runs of the app.  There are two types of long term storage:

Local Storage

Store information on the mobile device to be retrieved each time the app runs.

For example, a user address or high game score.

Cloud Storage

Store information on the web (cloud) so all app users can access the information.

For example, game leaderboard or chat messages.

LOCAL STORAGE

Once the user closes an app, the values of all variables get erased from the device’s memory. 

If you want to store data for the app between runs, you will use the TinyDB component

TinyDB can be used to store a user’s personal information that does not need to be shared.

For example, the user wants to enter their name, age, address once, not every time they use the app.  Another example is tracking something like healthy habits over time. 

TinyDB stands for Tiny Database. A database is an organized collection of data. You as the programmer decide how it is organized. 

TinyDB can be found in the Storage drawer in the Designer. 

TinyDB is a non-visible component, so you won’t see it appear on the screen when you add it to your project.

To access data in TinyDB you give each data item a tag, just like you give variables names. You store and get the value of the tag just like you set and get variable values. This is known as a tag-value pair.

StoreValue block

TinyDB.StoreValue stores the new value in TinyDB. You must specify the tag and the value to store.

TinyDB.GetValue block

TinyDB.GetValue gets the current value. 

valueIfTagNotThere is needed in case nothing has been stored previously with that tag.

CLOUD STORAGE

Cloud Storage allows any user of the app to access and share data.

TinyDB
3 phones pointing to single database
Cloud Storage

App Inventor has three viable cloud storage options.

Best practices: Always store a backup of your data somewhere! It’s very easy to delete or accidentally change your data, so make sure to store an extra copy somewhere safe!

In App Inventor you learn the term Tag-Value pair and this is used in real life coding a lot though we call it a Key-Value pair! Now you know the terms the experts use!

Guiding Questions to ask students: Where do you think cloud data is stored? You upload it to a website like google, youtube, tiktok etc but where is it stored after that? Where is the cloud? Companies like Google have HUGE buildings with computers just to store stuff in the cloud. So the joke is: “It’s not stored on the cloud, just someone else’s computer”. Amazon’s data storage:

Mentor tips are provided by support from AmeriCorps.

stylized A, AmeriCorps logo in navy

ACTIVITY: STORE GAME SCORES

Estimated time: 60 minutes

Update the Quick Quiz Game to Store High Scores

  1. Open the starter project in the App Inventor Gallery.
    Link in video is incorrect! Starter project link is https://bit.ly/appinventor-quick-quiz
  2. Load it into App Inventor so you can edit your own copy.
  3. Follow along with the video below to link a Google Sheet to your app to store and update players' high scores.
Open Starter Project

CHALLENGE

Now that you have coded the Quick Quiz game to read, write and update personal high scores, can you:

  1. Read the high scores of all players and find the highest score of all players
  2. Report that information to the user
    • using a label
    • or add it to the Alert message

REFLECTION

If you are going to store data for your app, you will need the information learned in this lesson. As you start to code your own app for your project, consider these questions.

strings of numbers
What data will you need to store for your app?
Does it need to be stored
in the app,
on the user's mobile device,
or in the cloud for sharing
Is it a combination of storage requirements for your app? You can use all 3 options!

REVIEW OF KEY TERMS

  • Database – an organized collection of information
  • Cloud Storage – information that is stored on the web so that any device connected to the internet can access it
  • Tag-value pair – a way to store and access information in a database

ADDITIONAL RESOURCES

Here are more documents and tutorials for exploring cloud storage in App Inventor.