In this lesson, we'll discuss a one-click love message app that sends a text to your significant other(s). In the process, you'll learn about the Texting component and user-generated, persistent data.
key properties: PhoneNumber and Message
key method: SendMessage
key event: MessageReceived
Demo: Love You App with custom message.
Description: one click method of texting your special loved one.
1. Add a label, a textbox, a submit button, a send button, a Texting component, and a TinyDB component.
2. Put default text in label and put a hint in the Textbox
3. In blocks editor, click event sends the text in label.
4. Click submit to a) change contents of label, and 2) blank out textbox.
5. Run it, change what's in the text box. If the app is closed and re-run, what will be the custom response?
PersistenceThe data stored in variables and component properties is called transient data.
Transient data dies (is de-allocated) when an app is closed.
If you reopen the app, it won't be there.
Persistent data is database data. It lives even after an app is closed.
If you reopen the app, you can access the persistent data.
TinyDB component in App Inventor
TinyDB lets you store and retrieve persistent data in a database on your phone. You tag the data, which means to give it a name it in the database. Here are some sample blocks:
Notice that the tag is the same so it will get the previously entered data.
In the Love You App, when should you call StoreValue? When would you call GetValue to retrieve the data from the database?
Careful: with persistent data, you need to think about the first time the app is run. What will be in the database then?
1. Add in code for storing/retrieving from TinyDB. Retrieve in Screen.Initialize. You can store on the send (or a separate button). Careful: TinyDB doesn't work with live testing. To test, download the app to your phone (Package for Phone | Show Barcode or Download to connected phone)
2. Note that the default message is squashed on first run of the app. Check for this in Screen.Init (check if the length of the text returned is 0).
Try it Part 1. Create your own one-click send-a-message app. First create it without persistence (TinyDB). It should have the following features:
Part 2. Add persistence to your app
After completing part2, save it as something like "Love You Honey". Then click SaveAs and name the new one something like "Love You Honeys", and go on to part 3.
Part 2. Let the user send the text to up to three numbers, and let the user change those numbers in textboxes. Be sure and save the numbers persistently. Save and then SaveAs again to begin the third version.
Part 3. Modify the app so that the user can change the numbers that are called by choosing them from the contacts list (instead of entering them in text boxes).
Part 4, extra credit: Let the user choose as many phone numbers as desired, instead of just three. You'll need a list for this, see chapter 19 in the book.