Inserting data into database
Inserting data into the database using Anko SQLite is a piece of cake. In this recipe, we will learn how to do that.
Getting ready
I'll be using Android Studio 3 to write code. You can get started by adding anko-sqlite dependencies to your project by adding the following lines to your build.gradle
file:
dependencies {
compile "org.jetbrains.anko:anko-sqlite:$anko_version"
}
You can replace $anko_version
with the latest version of the library.
How to do it…
Let's insert data into our database by following the mentioned steps:
- Let's start with our database helper, in which we will be creating a
Requests
table with thename
,message
, andid
fields, as follows:
class DatabaseHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "SupportDatabase", null, 1) { companion object { private var instance: DatabaseHelper? = null @Synchronized fun getInstance(context: Context): DatabaseHelper { if (instance == null) { instance...