3 Memory Android
3 Memory Android
Apps themselves are stored within internal storage by default. If your APK
size is very large, however, you can indicate a preference within your app's
manifest file to install your app on external storage instead:
<manifest ...
android:installLocation="preferExternal">
...
</manifest>
Data storage
Android provides several options for you to save persistent app data. The
solution you choose depends on your specific needs, such as whether the
data should be private to your app or accessible to other apps (and the
user) and how much space your data requires.
Your data storage options include the following:
Files
Android uses a file system that's similar to disk-based file systems on
other platforms such as Linux. File-based operations should be familiar to
anyone who has used Linux file I/O or the java.io package.
All Android devices have two file storage areas: "internal" and "external"
storage. These names come from the early days of Android, when most
devices offered built-in non-volatile memory (internal storage), plus a
removable storage medium such as a micro SD card (external storage).
Today, some devices divide the permanent storage space into "internal"
and "external" partitions, so even without a removable storage medium,
there are always two storage spaces and the API behavior is the same
whether the external storage is removable or not. The following lists
summarize the facts about each storage space.
Only your app can access files. World-readable. Any app can read.
Specifically, your app's internal storage
directory is specified by your app's
package name in a special location of
the Android file system. Other apps
cannot browse your internal directories
and do not have read or write access
unless you explicitly set the files to be
readable or writable.
When the user uninstalls your app, the When the user uninstalls your app,
system removes all your app's files the system removes your app's files
from internal storage. from here only if you save them in
the directory
from getExternalFilesDir().
Internal storage is best when you want External storage is the best place
to be sure that neither the user nor for files that don't require access
other apps can access your files. restrictions and for files that you
want to share with other apps or
allow the user to access with a
computer.
Internal storage
You don't need any permissions to save files on the internal storage. Your
app always has permission to read and write files in its internal storage
directory.
External storage
Use external storage for files that should be permanently stored, even if
your app is uninstalled, and be available freely to other users and apps,
such as pictures, drawings, or documents made by your app.
Some private files that are of no value to other apps can also be stored
on external storage. Such files might be additional downloaded app
resources, or temporary media files. Make sure you delete those when
your app is uninstalled.
https://google-developer-training.github.io/android-developer-fundamentals-
course-concepts-v2/unit-4-saving-user-data/lesson-10-storing-data-with-room/
10-0-c-sqlite-primer/10-0-c-sqlite-primer.html
SQL databases
SQL databases store data in tables of rows and columns:
The intersection of a row and column is called a field.
Fields contain data, references to other fields, or references to other
tables.
Rows are identified by unique IDs.
Columns are identified by names that are unique per table.
Think of a database as a spreadsheet with rows, columns, and cells,
where cells can contain data, references to other cells, and links to
other sheets.
Database for Android App
Where can you save app data?
Locally
Files on SD Card
SQLite Database
Cloud
API Services
SQL Server (MS SQL, MySQL etc)
Google Firebase, Microsoft Azure, Mongo DB
SQLite
SQLite is a software library. SQLite implements an SQL database engine
that has the following characteristics:
Self-contained (requires no other components)
Serverless (requires no server backend)
Zero-configuration (does not need to be configured for your app)
Transactional (changes within a single transaction in SQLite either
occur completely or not at all)
SQLite is the most widely deployed database engine in the world. The
source code for SQLite is in the public domain.
SQLite Database:
SQLite is a software library that provides a relational database
management system. The lite in SQLite means lightweight in terms of
setup, database administration, and required resources.
Self-Contained
SQLite is self-contained means it requires minimal support from the operating
system or external library. This makes SQLite usable in any environment
especially in embedded devices like iPhones, Android phones, game consoles,
handheld media players, etc.
SQLite is developed using ANSI-C. The source code is available as a big sqlite3.c
and its header file sqlite3.h. If you want to develop an application that uses
SQLite, you just need to drop these files into your project and compile it with
your code.
Zero-configuration
Because of the serverless architecture, you don’t need to “install” SQLite before
using it. There is no server process that needs to be configured, started, and
stopped.
Transactional
All transactions in SQLite are fully ACID-compliant. It means all queries and
changes are Atomic, Consistent, Isolated, and Durable.
In other words, all changes within a transaction take place completely or not at
all even when an unexpected situation like application crash, power failure, or
operating system crash occurs.
Transactions
A transaction is a sequence of operations performed as a single
logical unit of work. A logical unit of work must exhibit four
properties, called the atomicity, consistency, isolation, and durability
(ACID) properties, to qualify as a transaction:
Examples of transactions:
Transferring money from a savings account to a checking account.
More on SQLite:
SQLite is an open source SQL database that stores data to a text file on a device.
Android comes in with built in SQLite database implementation.
SQLite supports all the relational database features. In order to access this
database, you don't need to establish any kind of connections for it like
JDBC,ODBC e.t.c
SQLite is an embedded SQL database engine. Unlike most other SQL databases,
SQLite does not have a separate server process. SQLite reads and writes directly
to ordinary disk files. A complete SQL database with multiple tables, indices,
triggers, and views, is contained in a single disk file. The database file format is
cross-platform - you can freely copy a database between 32-bit and 64-bit
systems. These features make SQLite a popular choice as an Application File
Format.