April 26, 2025

 Storing Data in App Inventor

0

In This Lesson You Will …

  • 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

Let’s revisit the options and review some key considerations [please note, App Inventor is no longer supported, but the concepts are still relevant for building apps with other tools]:

  • Local Storage (TinyDB): Perfect for storing data specific to each user’s device.
    • Pros: Simple, works offline, great for smaller amounts of personal data.
    • Cons: Data is only available on the device, not accessible across multiple devices.
  • Cloud Storage: Ideal for data that needs to be shared among users or accessed from different devices.
    • Pros: Data is shared across devices, works with multiple users.
    • Cons: Requires internet connectivity to save/load data. Setting up cloud databases can be more complex.
  • Choosing: Ask yourself if your data is user-specific (like high scores or saved progress) or shared (like a leaderboard or global chat). If offline access is essential, local storage is the clear choice. Otherwise, consider cloud storage for its collaborative advantages.
  • Additional Points:
    • The “App Inventor” extensions mentioned are now outdated. Many functions have moved to the main App Inventor platform.
    • Look for tutorials on using the new storage components within App Inventor on the MIT App Inventor website: https://appinventor.mit.edu/

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.

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

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

Cloud Storage

App Inventor has three viable cloud storage options.

CloudDB

FirebaseDB

Google Spreadsheets

CloudDB is a component and database service provided by MIT App Inventor.

CloudDB works just like TinyDB. You store and access data using tag-value pairs.

CloudDB is accessed from the Storage drawer. It is a non-visible component so it won’t appear on the Screen when you add it.

Storing data works the same as TinyDB.

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

You can store different types of data. For example, in these blocks, highScore is a number. chat is a list of messages.

Getting data works similar to TinyDB, but with an extra step. Because the database is in the cloud, the app needs to ask to get the value and wait for a response. So an event handler block is needed to signal when the database responds with the data.

GetValue notifies the database the app wants information. valueIfTagNotThere should be the correct data type for the tag. For example, a number or a list.

GotValue is triggered once the database responds with the information. If you have multiple tags in an app, you need an if block to check for the correct tag before using the value. A close-up of a computer screen

AI-generated content may be incorrect.

Mentor Tip

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.

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!

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!

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.

Leave a Reply

Your email address will not be published. Required fields are marked *