Record Sensor Data into a SQLite Database

To see how useful a database can be, let’s go one step further and create an app that lets us record sensor data directly into a SQLite database table. We’ll then use SQL queries to browse the sensor data we’ve recorded from the accelerometer and visualize the data on the Android screen as a time series.[246] A time series plots data points recorded at fixed intervals. For our example, we will record a data point every time we receive a new accelerometer value.

Alongside the accelerometer sensor values x, y, and z, we’ll record time as Unix time (measured in milliseconds since January 1, 1970 UTC[247]) using Android’s System method, currentTimeMillis.[248] This allows us to identify precisely at what ...

Get Rapid Android Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.