Android and Sqlite – Using Database

Article will guide users through several lessons, from setting up development environment, creating database with generic record adding, driving control to the user giving him options to add, modify and delete records.

Lesson  I

Setting up Eclipse for Android application development

Hi everybody,

Several  weeks ago I have started working on Android application which will have support from SQLite database, simple phone book, nothing special. However, making such application can cause a lot of headache, especially for beginners. Although there were large amount of books for Android on the market, I have the feeling that every one of them just scratch on the surface of certain topic and move on. It is understandable, there is a lot of ground to cover, and writing the book which will cover all the topics is impossible. So, I decided to share with you my experiences about SQLite database topic. This approach isn`t probably the best one, it is certainly not the only one, it`s just the way I did it. I hope someone fill find this useful, and my intent is to have all important aspects in one place. Since there is a lot of ground to cover, I decided to break tutorial on several lessons. So let`s roll. First lesson will cover basic setup of Eclipse IDE so we can start working on Android projects. If you already have set up environment, you can skip this lesson.  We need several things before we can go any further. First thing is java development kit (jdk). So type following address in your browser:

https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jdk-6u23-oth-JPR@CDS-CDS_Developer

select your operating system version, check licence agreement and you will be redirected to download page. Download it and install it on default location.

Get the My Triond Articles widget and many other great free widgets at Widgetbox! Not seeing a widget? (More info)

Next, we need Eclipse IDE, so head up on the following location:

http://www.eclipse.org/downloads/ and select version from the picture bellow:

Select the appropriate version of your OS (32bit or 64bit) and pick the mirror and start download. After package has been downloaded, just unpack it on whatever location on your disk and that`s it.

Next, we need  android SDK so let`s head on to following location:

http://developer.android.com/sdk/index.html and pick the archive like in the picture bellow:

Android_sdk_r08-windows.zip (for windows OS). Download it and unpack it on desired location. Open extracted folder and you will see following files and directories:

Select and start SDK Manager and it will open dialog with sdk packages to install:

If you want to select and install all packages click install, be aware however that this can take some time. So if you want to install just some of the packages, select from the left screen one you don`t want, and click reject. To be quick, I have installed just API 9 and API 8, documentation for API 9 and Android SDK Platform tools (just top four). New dialog will appear showing installation progress:

When download is completed, we can see list of the installed packages:

Let`s now create virtual device which we will use for our application testing. Select Virtual Devices from the left menu and you will see the following:

As we can see, there is no devices, we will create one. Click on New… button on the right side and it will open create new Android Virtual Device (AVD):

Enter virtual device name (TwoTwo), pick target platform (since I installed API 8 and API 9 only, I have only this two devices), in my case Android 2.2 – API Level 8, enter SD Card memory (512 in my case) and that`s it – click Create AVD. New virtual device is created:

Focus  on it and click on Start… this will launch Android Virtual Device, and after some time you will see following:


This is Android emulator, and as you can see, we create it and start it without ever starting eclipse. But, in order to create Android projects and test them on newly created virtual device, we will have to somehow connect AVD with eclipse. So fire up eclipse IDE. When Eclipse is started, click on Help -> Install New Software… and new window will open and you will be prompted to enter link to desired software you want to install:

We need ADT plugin for Eclipse, so enter following into Work With… field:

https://dl-ssl.google.com/android/eclipse/  – Developer Tools will be listed on the main area of the window, so check everything and click next and finish, and after some time ADT plugin will be installed.

Restart Eclipse, and click on Window -> preferences new dialog opens:

Click on the Android on the left side and browse to the SDK we download at the beginning. We have to tell Eclipse where is the SDK In order to work with Android projects. Click OK to close the dialog. New icon will appear on Eclipse toolbar:

We can now open AVD Manager directly from eclipse, and we already have virtual device created and started. One more thing to do, create new android project. Click File -> New -> Project…, dialog will open:

Expand Android and pick Android Project. This will open following:

Enter the name of the project (HelloAndroid), pick the build Target (Android 2.2 since I created and started this virtual device), enter Application name, package name, create activity and Min SDK Version, like following:

Project Name: HelloAndroid

Build Target: Android 2.2

Application Name: HelloAndroid

Package name: org.example.helloandroid

Create Activity: HelloAndroid

MIN SDK version: 8

Click Finish. This will create new project. Launch it by clicking on the white triangle in green circle:

 and after some time it will start and write HelloAndroid onto our virtual device screen:

 It will be wise to start Virtual Device at the beginning and use it while your Eclipse IDE is started, because it will save us great amount of time since we don`t have to start it each time we want to deploy our application on it for testing. As we can see, we started application in emulator without writing single line of code. However, to something useful , we will have to start coding. One note at the end, sometimes, when switching between the projects while using one virtual device,  it might happened that virtual device showing results from previous project. Just shut down It and start it again. You can follow up what is going on by turning Console Perspective. You can do it by clicking on Window ->Show View -> Console, just like following picture shows:

It will show it on the lower part of Eclipse IDE as a TAB. You can detach it on the special screen. What ever you like. Let`s keep it on since we will need it later. We will also need two more views but we will open them latter. That`s the topic of our next lesson. 

Lesson II: (http://computersight.com/software/android-and-sqlite-using-database-part-two/)

Also, check my iPhone programming tutorial at http://computersight.com/computers/iphone-multiview-application-part-i/

Jose
10.12.26

Excelente post, lo seguí al pie de la letra y funcionó perfectamente. Muchas Gracias amigo.

Sally
10.12.26

Good sharing

comments powered by Disqus
Loading