1 / 9

Programming with App Inventor

Programming with App Inventor. Computing Institute for K-12 Teachers Summer 2012 Workshop. Advanced Topics 1 Session SA-6. Data Storage. The App Inventor provides simple database capabilities to store information needed or created by your program.

kara
Download Presentation

Programming with App Inventor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop

  2. Advanced Topics 1Session SA-6

  3. Data Storage • The AppInventor provides simple database capabilities to store information needed or created by your program. • This information, once stored, will be available to you after your device (Android phone or tablet) application has ended and even after the Android device has been powered off. This is persistent memory that will be available until it is specifically deleted. • The data can be save either online or on your device’s local memory (SIM card). • The two objects provided are called the tinyDBand tinyWebDB. • The tinyDB is listed among the objects in the BasicPalette • But no matter how you combine them, Boolean expressions evaluate to either True or False.

  4. Data Storage • The tinyWebDBis listed in the Palette in the App Designer under the Other stuff section. • The tinyWebDB has one attribute in the Propertiesthat can be modified, the ServiceURLor online locationof the database server. No location is provided for the local database of the tinyDB. • TinyWebDb by default uses a shared testing databasethat is used by all AppInventors. Your data saved in this testing database will eventually be overwritten. • You may create a ‘private’ shared database that willlimit which users have access. • The instructions for creating the ‘private’ database arelocated online with the help for the tinyWebDB object.

  5. Data Storage • Both DB objects work exactly the same way with respect to storing data. • Data stored to these databases is stored under a unique tag generated by your program. A ‘tag’ is used as an easy way to identify what you have stored. Important: The tag must be unique. • For example, if you store a List under the tag ‘answerList’ and the store another List under that same tag ‘answerList’, you will have overwritten the first List losing you data. • The following two blocks (associated with both the tiny and tinyWeb DB objects store information: • You need to provide the unique tag for each of the values to stored. • But no matter how you combine them, Boolean expressions evaluate to either True or False.

  6. Data Storage • Retrieving data using the DB Objects varies slightly. • The tinyDB provides a .StoreValue block and a simple .GetValue block which returns the value associated with the tag. • The tinyWebDB needs slightly different methods since there is a web server that provides for communication across the Internet. • Basically, with the tinyWebDB, you send a command to the db web server and then wait for the web server to signal back (via an event block) that the command has completed. • With the tinyDB, the .GetValue command actually retrieves the data from the local database which you can assign to a local variable Events

  7. Data Storage.GotValue Event • After initiating the .GetValue for the tinyWebDB, you must use the .GotValue event block to obtain the data from the online data base. You need to compare the tagFromWebDB value to the tag under which the data was originally stored to determine what data was is be read. Below is sample code that executed when the online db signals the data has been retrieved. • This code executed in this block is a primeexample of where a procedure could beutilized. • To view yours (and others) data save online,browse to the ServiceURL provided in the properties for the tinyWebDB. • If you create a ‘private’ shared online database, the ServiceURL will be slightly different. • View the testing database:http://appinvtinywebdb.appspot.com • Viewing the online database can be veryhelpful in making sure your data was stored.

  8. Data Storage.WebServiceError Event • There is one other event for the tinyWebDB called .WebServiceError that can be ‘handled’ to report when the online database is having problems. If .StoreValue has been initiated and the Internet connection is not available or the database is not responding, this event maybe trigger and provide helpful information. • The block below show how to set the text of a label to the error message returned when there is a WebServiceError.

  9. Sample 6 Lists & TinyWebDB • Make Quiz

More Related