Spring 2022 MAI203 – Tech Bots w/ MIT AI2 Computer Storage and Cloud Storage https://appathon.appinventor.mit.edu/ Let us work together to take you to the winning stages. Hackathons Dr. R. Feng https://gallery.appinventor.mit.edu/?galleryid=ac3e3f9c-d650-47bb-8f8c-3231e5bc83a0 4 Dr. R. Feng Why do we need storage? Cloud Storage CPU Memory Random Access Memory Dr. R. Feng Why do we need storage? Storage Dr. R. Feng Why do we need storage? - Information such as variables are temporary When the app is restarted, the memory is cleared and you lose information. File Storage: - Allows you to read/write text data from a file. Applications: event logging, exporting data, etc More permanent form of storage → will stay on your device until the file is deleted Dr. R. Feng File Manipulation Functions Adds the input text to the end of the designated file. Ex. File1.txt contains “oldtext” File1.AppendToFile(“newtext”, “File1.txt”) → File1.txt contains “oldtextnewtext” Deletes the designated file * You cannot do this with protected files Retrieves the text from the designated file Saves input text to a file If the file already exists, it will overwrite the contents of the file Dr. R. Feng File Events Triggers after the file has successfully saved. Means that the contents have already been written and confirms that there were no errors in the writing process. Triggers after text is successfully retrieved from the file. Only way to confirm a file can be read and to access the text. Dr. R. Feng External Files Files located elsewhere on your device. Use slashes to denote the file’s directory, and use a leading slash to tell your app to look outside of its private folder Ex. Will look in storage → Download → filename.txt Will look in storage → app private folder → Download → filename.txt Dr. R. Feng App Data Files Files located in sdcard (or phone internal storage) → AppInventor → data Access files by using the file’s name ⇒ If you are on the companion, will read from AppInventor/data ⇒ If as a packaged app (.apk), will read from the app’s private directory This means that other programs will not be able to access it! Dr. R. Feng Asset Files Packaged with the application (.apk file) Use “//” at the beginning of the fileName variable to tell the code to look in the app’s asset files Since asset files are packaged with the app, you cannot modify or delete them Dr. R. Feng Overview: Reading from files 1. “Filename.txt” a. Reads from the app’s private directory b. Not accessible by other apps c. Use for data that you need to save but is not needed elsewhere 2. “/Filename.txt” a. Reads from your device’s sdcard or internal storage b. Can be accessed by other apps c. Use for exporting data from your app 3. “//Filename.txt” a. Reads from app’s asset files b. Cannot be deleted or modified c. Use for storing information the app needs on startup Dr. R. Feng CloudDB: Online Storage Allows you to store data on an Internet connected server (Redis software) Users of the app can share data with each other → All users will share the same server! CloudDB stores data based on a tag system, much like a dictionary Tag, Data Dr. R. Feng CloudDB Methods Appends the designated item to the end of the list under the given tag. * Multiple users can append at the same time Clears the data under the given tag Returns true/false based on whether the app is connected to CloudDB Retrieves a list of tags from CloudDB Dr. R. Feng CloudDB Methods Cont. Retrieves the value at the given tag Returns a specific value if the tag is not found Removes the first item of the list located at the specific tag Stores the value at the specified tag. Dr. R. Feng CloudDB Events Specifies actions if an error is encountered. Specifies actions when data on CloudDB is changed Triggered by the function RemoveFirstFromList Triggered when a value is successfully retrieved Triggers when the tag list is successfully retrieved Dr. R. Feng List View, Spinner, and ListPicker Dr. R. Feng Walkthrough Project # 1 Implement an app to create a file, append text to the file, and then delete the file. Pay attention to the events the file component has. Understand event invocations can be available in software objects or components, in additions to human beings. Dr. R. Feng Walkthrough Project # 2 Implment an app to store data in the cloud using CloudDB, retrieve data from the CloudDB, and display the data with ListView, Spinner, or ListPicker. Dr. R. Feng Dr. R. Feng