Test your knowledge of local storage concepts with this quiz focused on SQLite databases and Shared Preferences. Learn the basics, key differences, and correct usage scenarios to master local data storage methods for applications.
Which data type is commonly used when storing integer values in an SQLite table?
Explanation: The correct data type for storing whole numbers in SQLite is INTEGER. STRING and INTTEXT are not valid SQLite data types; STRING is usually replaced with TEXT and INTTEXT does not exist. FLOAT is for decimal numbers, not integers.
What is the primary use of Shared Preferences in local storage?
Explanation: Shared Preferences are mainly used to store simple key-value pairs such as user settings or preferences. They are not intended for large files or complex relational data, and have nothing to do with running background tasks. Using them outside their scope can result in inefficient design.
Which command is used to create a new table in SQLite?
Explanation: The CREATE TABLE command is the standard way to make a new table in SQLite. Options like INSERT TABLE and FORM TABLE are incorrect commands, and MAKETABLE is not recognized. Using the wrong syntax will result in errors.
How long does data typically persist in Shared Preferences unless it is explicitly removed?
Explanation: Data stored in Shared Preferences remains until it is manually deleted by the application or the user uninstalls the app. App updates or device restarts do not remove this data. There is also no default automatic expiration after a day.
What is the best storage option for saving complex relational data with multiple related tables?
Explanation: SQLite is designed to handle complex relational data with multiple tables and relationships. Shared Preferences is meant for simple key-value storage and cannot manage relations. The Clipboard and Preferences Table are unrelated to local database storage.
Which data types can typically be stored using Shared Preferences?
Explanation: Shared Preferences support simple data types like strings, integers, booleans, floats, and sometimes longs. They are not intended for storing images, videos, full tables, or custom class objects. Attempting to do so will result in data loss or errors.
Which command retrieves data rows from a table in SQLite?
Explanation: The SELECT command is used to query and retrieve rows from a SQLite table. GET FROM and SHOW TABLE are not valid SQL commands, and PUT is used for uploading or updating, not retrieving.
Where are Shared Preferences typically stored on a device?
Explanation: Shared Preferences are saved locally in an app-specific area that other apps cannot access. They are not stored on remote servers or in the cloud by default, and not exclusively on a memory card. This enhances security and privacy for stored data.
What is a typical characteristic of SQLite regarding data storage limits?
Explanation: SQLite can handle considerable databases with many records and complex structures, though practical limits depend on device resources. There is no inherent 10-record or 100 MB file limit, and every system has resource constraints, making 'no limit' inaccurate.
What happens if you store a value with an existing key in Shared Preferences?
Explanation: When a value is saved with an existing key, Shared Preferences replace the old value with the new one. It does not keep both, create multiple entries, or produce an error; the key-value pair simply gets updated.
Which SQL command updates data in an existing SQLite table row?
Explanation: The UPDATE command modifies existing data in a SQLite table. CHANGE, REFRESH, and MODIFY are not valid SQL commands; attempting to use them would lead to syntax errors.
Why are transactions used when working with SQLite databases?
Explanation: Transactions help maintain data consistency by ensuring a group of operations are completed fully or not at all. They do not relate to playing videos, deleting databases, or sending emails. This mechanism is essential for reliable database operations.
In what format is Shared Preferences data typically stored locally?
Explanation: Shared Preferences are usually stored as plain text XML files, making them easy to read but not highly secure. They are not stored as binary, images, or CSV files. This choice is made for compatibility and simplicity.
Which SQL command is used to remove records from a table in SQLite?
Explanation: The DELETE command removes records from a table according to specified criteria. REMOVE and ERASE are not recognized SQL commands, and DROP DATABASE is used for dropping databases, not records.
What is one common use case for Shared Preferences with user accounts?
Explanation: A common use for Shared Preferences is saving a user's login state or session details between app launches. It's not ideal for images, cataloging products, or handling complex queries, all of which require more advanced storage or processing solutions.
Which statement best describes the security of data stored in SQLite and Shared Preferences by default?
Explanation: By default, both storage methods restrict access to the application itself but do not encrypt the data automatically. Unless extra measures are taken, the data is not publically available to all apps, nor is it fully encrypted. Both methods can indeed store user data.