Many apps have data that is stored in a web server and shared amongst users and devices. Facebook and Twitter are that way, of course. If you've built the Note Taker app, or the song recording app, they are not-- each user only stores the data on their device, privately. But both of those apps could be modified for sharing-- think of a note taking app in which notes are shared with a group of the public (Twitter!) or a song recording app that lets you share your songs with others. In this lesson, you'll learn how to build such apps with App Inventor.TinyWebDB is the key component you'll need. It is an App Inventor component that let's your app store persistent data on the web and share data amongst phones and people. It has similar blocks as TinyDB, but the data is stored on the web instead of privately on the device. Key points about TinyWebDB:
TinyWebDB has a property SourceURL. You can set it to any App Inventor compliant web service, that is, any site that has been setup especially for use with App Inventor and TinyWebDB. By default, TinyWebDB stores data at appinvtinywebdb.appspot.com. Be careful, though, as this web database is shared amongst all App Inventor programmers. It also has a limit of 100 total entries and thus is for testing purposes only.
For your creative apps, you should create your own TinyWebDB service. No coding is required. See appinventorapi.com/program-an-api-python for instructions.
TinyWebDB provides similar functions to TinyDB: StoreValue and GetValue. StoreValue works exactly the same, but GetValue works a bit differently-- it is asynchronous. When you call GetValue, you're really just requesting the data and the data isn't immediately returned. Instead, you must code the GotValue event-handler, which is triggered when data actually arrives from the web.
Consider the following sample, which is taken from two version of a note taking app, one for private note taking, the other for sharing notes:
In the TinyDB solution, the app calls GetValue and checks if the data is a list (it won't be the first time the app is run, before any notes are added). If the data is a list, it is placed in the variable NoteList and the list is displayed (DisplayList is a procedure, not shown, that shows the notes in a label).
In the TinyWebDB solution, GetValue is again called from within Screen.Initialize, but note that it returns no data. The TinyWebDB.GetValue block doesn't have anything coming out the left that can be plugged in to a slot. Instead, the GetValue just sends a request to the web. Eventually, the data will arrive, and then the GotValue event-handler is triggered. When it is, the TagFromWebDB gives you the tag of the request and the valueFromWebDB is the data that was requested (the list of notes). As you can see, the data is processed in a similar manner to the TinyDB solution.
Now use TinyWebDB for real. Take one of your apps you've built and convert it. To test it, you'll want to have your app installed on multiple devices, and see if the devices can share data. Check out the videos to the right as a guide.