SQLite Database
SQLite Database:
Android SQLite Database is a RDBMS, lightweight and that comes shipped with the Android Operating System that offers a Local Data Storage solution to Andoird applications.
SQLite is C library that offers scalable and lightweight client-side database which requires no server and is easy to configure.
In the context of Android development, SQLite is a utility that provides the application with a database for structured data which could be written in a persistent memory in the device.
Example:
<!-- activity_main.xml --≶
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="16dp"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="ID"
android:layout_margin="10dp"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:layout_margin="10dp"/>
<EditText
android:id="@+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Age"
android:layout_margin="10dp"
android:inputType="number"/>
<EditText
android:id="@+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="City"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:gravity="center_horizontal">
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:layout_weight="1"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
android:layout_margin="10dp"/>
<Button
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View"
android:layout_weight="1"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
android:layout_margin="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="6dp"
android:gravity="center_horizontal">
<Button
android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update"
android:layout_weight="1"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
android:layout_margin="10dp"/>
<Button
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete"
android:layout_weight="1"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
android:layout_margin="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="6dp"
android:gravity="center_horizontal">
<Button
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search"
android:layout_weight="1"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
android:layout_margin="10dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
// activity_second.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity"
android:padding="16dp">
<TextView
android:id="@+id/viewSavedData"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="View Saved Data"
android:textSize="18sp"
android:padding="8dp"
android:textColor="#000000"
android:scrollbars="vertical"/>
</ScrollView>