concept TinyDB in category python

appears as: TinyDB, TinyDB
Hello App Inventor!: Android programming for kids and the rest of us

This is an excerpt from Manning's book Hello App Inventor!: Android programming for kids and the rest of us.

The second screen can be simple: it has a button with the text “Tell me your dream”. The text produced by the speech recognizer will appear below the button in a label. Putting this part of the app together means you need to know how to store data in the TinyDB database; take a look at the Learning Point “Storing data in TinyDB.”

Learning Point: Storing data in TinyDB

The introduction of the TinyDB component takes things to another level and allows you to store information when the app is closed. Nearly every app or program has a database of some kind that needs to be added to. For example, it could be used to keep track of the highest score for a game.

App Inventor has a great component called TinyDB that allows you to use some of the advanced functions of a database without having advanced knowledge. In the My Dream Recorder app, for example, the TinyDB component allows you to store some text (your dream description). Then, when you next open the app, the text is still there. This is called persistent data—it’s obstinate and stays there despite you switching off the app! This is in contrast to non-persistent data, which gives up easily. For example, in the Cheeky Hamster app that you created in chapter 6, as each seed lands in the bowl, you score a point. But even if you run up a huge score, when you reopen the app, the score returns to 0. This is because although you dutifully use a variable to store and add to the score while the app is open, there is nowhere to store it once the app is closed; so the score resets to its default of 0.