Database Development In Android Applications

Similar documents
ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

An Android Studio SQLite Database Tutorial

Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence

SQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite

User Interface Development in Android Applications

07. Data Storage

SQLite Database. References. Overview. Structured Databases

Mobile Computing Practice # 2d Android Applications Local DB

Mobile Programming Lecture 10. ContentProviders

Learn about Android Content Providers and SQLite

Create a local SQL database hosting a CUSTOMER table. Each customer includes [id, name, phone]. Do the work inside Threads and Asynctasks.

Basic GUI elements - exercises

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

CSCU9YH: Development with Android

Create Parent Activity and pass its information to Child Activity using Intents.

Vienos veiklos būsena. Theory

android:layout_margintop="5dp" > <EditText android:layout_width="210dp"

Android: Data Storage

Computer Science E-76 Building Mobile Applications


Practical 1.ListView example

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

ELET4133: Embedded Systems. Topic 15 Sensors

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Android Programs Day 5

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Mobile and Ubiquitous Computing: Android Programming (part 4)

Managing Data. However, we'll be looking at two other forms of persistence today: (shared) preferences, and databases.

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

else if(rb2.ischecked()) {

Intents. Your first app assignment

Simple Currency Converter

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Data Persistence. Chapter 10

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

MyDatabaseHelper. public static final String TABLE_NAME = "tbl_bio";

Dynamically Create Admob Banner and Interstitial Ads

Lecture 14. Android Application Development

<uses-permission android:name="android.permission.internet"/>

Custom Views in Android Tutorial

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Adapter.

Android Services. Victor Matos Cleveland State University. Services

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Arrays of Buttons. Inside Android

LifeStreet Media Android Publisher SDK Integration Guide

App Development for Smart Devices. Lec #7: Audio, Video & Telephony Try It Out

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

CS378 -Mobile Computing. Persistence -SQLite

Advanced Android Development

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

The Basis of Data. Steven R. Bagley

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Android Apps Development for Mobile Game Lesson 5

Android HelloWorld - Example. Tushar B. Kute,

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Android Application Development. By : Shibaji Debnath

Android SQLite Database Tutorial - CRUD Operations


EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

EMBEDDED SYSTEMS PROGRAMMING Android Services

Starting Another Activity Preferences

Meniu. Create a project:

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

Android Data Storage

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

UNDERSTANDING ACTIVITIES

Embedded Systems Programming - PA8001

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

ANDROID PROGRAMS DAY 3

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

Our First Android Application

Manifest.xml. Activity.java

Debojyoti Jana (Roll ) Rajrupa Ghosh (Roll ) Sreya Sengupta (Roll )

Android Layout Types

Accelerating Information Technology Innovation

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Table of Content. CLOUDCHERRY Android SDK Manual

Android Application Model II. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Android - JSON Parser Tutorial

TPCT s College of Engineering, Osmanabad. Laboratory Manual SDL-II. Mobile Application Development (Android) For. Third Year Students (CSE)

05. RecyclerView and Styles

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

MOBILE APPLICATIONS PROGRAMMING

Sqlite Update Failed With Error Code 19 Android

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

Saving application preferences

GATAV 5. Animations Using a Game Loop

Android Beginners Workshop

Theme 2 Program Design. MVC and MVP

Accelerating Information Technology Innovation

Tabel mysql. Kode di PHP. Config.php. Service.php

Transcription:

ITU- FAO- DOA- TRCSL Training on Innovation & Application Development for E- Agriculture Database Development In Android Applications 11 th - 15 th December 2017 Peradeniya, Sri Lanka Shahryar Khan & Imran Tanveer, ITU Experts

Android Databases Agenda Sqlite Database Practical

Databases Sqlite Database: Android provides full support for SQLite databases. Any databases you create will be accessible by name to any class in the application, but not outside the application. The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the oncreate() method, in which you can execute a SQLite command to create tables in the database You can then get an instance of your SQLiteOpenHelper implementation using the constructor you've defined. To write to and read from the database, call getwritabledatabase() and getreadabledatabase(), respectively Every SQLite query will return a Cursor that points to all the rows found by the query. The Cursor is always the mechanism with which you can navigate results from a database query and read rows and columns. MainAcitvity.java import android.app.activity; import android.content.contentvalues; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.widget.textview; public class MainActivity extends Activity { EventDataSQLHelper eventsdata; TextView output; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); output = (TextView) findviewbyid(r.id.output); eventsdata = new EventDataSQLHelper(this); addevent("demo event"); Cursor cursor1 = getevents1(); showevents(cursor1);

public void ondestroy() { super.ondestroy(); eventsdata.close(); private void addevent(string title) { SQLiteDatabase db = eventsdata.getwritabledatabase(); ContentValues values = new ContentValues(); values.put(eventdatasqlhelper.time, System.currentTimeMillis()); values.put(eventdatasqlhelper.title, title); db.insert(eventdatasqlhelper.table1, null, values); private Cursor getevents1() { SQLiteDatabase db = eventsdata.getreadabledatabase(); Cursor cursor1 = db.query(eventdatasqlhelper.table1, null, null, null, null, null, null); return cursor1; private void showevents(cursor cursor) { StringBuilder ret = new StringBuilder("Saved Events:\n\n"); while (cursor.movetonext()) { long id = cursor.getlong(0); long time = cursor.getlong(1); String title = cursor.getstring(2); ret.append(id + ": " + time + ": " + title + "\n"); output.settext(ret); EventDataSQLHelper.java import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.util.log; /** Helper to the database, manages versions and creation */ public class EventDataSQLHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "events.db"; private static final int DATABASE_VERSION = 1;

// Table name public static final String TABLE1 = "events"; // Columns public static final String TIME = "time"; public static final String TITLE = "title"; public EventDataSQLHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); public void oncreate(sqlitedatabase db) { String sql = "create table " + TABLE1 + "( " + "id_" + " integer primary key autoincrement, " + TIME + " integer, " + TITLE + " text not null);"; Log.d("EventsData", "oncreate: " + sql); db.execsql(sql); { public void onupgrade(sqlitedatabase db, int oldversion, int newversion) if (oldversion >= newversion) return; String sql = null; if (oldversion == 1) sql = "alter table " + TABLE1 + " add note text;"; if (oldversion == 2) sql = ""; Log.d("EventsData", "onupgrade : " + sql); if (sql!= null ) db.execsql(sql);

activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/title" android:text="sqlite Database" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="120dp" android:textstyle="bold" android:textsize="26sp" android:layout_margintop="30dp"/> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/title"> <TextView android:id="@+id/output" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> </RelativeLayout>

Output