Archive for the ‘Android’ Category

How to use database in Android

March 15, 2012 3 comments

Android supports SQLite database. In this example we will see these following
1. How to create or open database.
2. How to create table in database.
3. How to insert data in database table.
4. How to fetch data from database table and show.

I tested this example with ‘Andorid-2.2, sdk version-8’.
Packege Name:
Activity Name: DbActivity
File Name:

Code starts here

package;//Packeage name

import android.os.Bundle;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.TextView;

public class DbActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
SQLiteDatabase myDB= null;
String TableName = “Profile”;
String ShowData=””;
/* This function create new database if not exists. */
try {
myDB = this.openOrCreateDatabase(“testdb”, MODE_PRIVATE, null);
/* Create a Table in the Database. */
+ TableName
+ ” (id INT(4),firstname VARCHAR,lastname VARCHAR);”);
/* Insert data to a Table*/
+ TableName
+ ” (id, firstname, lastname)”
+ ” VALUES (1, ‘Yaju’, ‘Kumar’);”);

/*Fetch data from database table */
Cursor c = myDB.rawQuery(“SELECT * FROM ” + TableName , null);

int id = c.getColumnIndex(“id”);
int fristName = c.getColumnIndex(“firstname”);
int lastName = c.getColumnIndex(“lastname”);

// Check result.
if (c != null) {
// Loop through all Results
do {
int personId = c.getInt(id);
String FirstName = c.getString(fristName);
String LastName = c.getString(lastName);
ShowData =ShowData +personId+” .) “+FirstName+” “+LastName+”\n”;
TextView tv = new TextView(this);
catch(Exception e) {
Log.e(“Error”, “Error”, e);
} finally {
if (myDB != null)


How to set application icon

September 22, 2011 2 comments

If you want to set your own application icon in Android then here is the solution. Please follow these step.
1. Put you icon in ‘res/drawable/’ directory.
2. Open your AndroidManifeast.xml file in code mode.
3. Find this attribute ‘android:icon=”@drawable/icon’ in this tag ‘<application’. Here icon is the your icon file name. Here you have two option either you can replace ‘icon’ name with you icon file name or save icon file by ‘icon’ name.
4. Run your Emulator. Now check applications list in the emulator the new application icon installed and ready.

How to install apk files on Android Emulator

September 7, 2011 6 comments

If you looking to test any application on android emulator. Please follow these step.

1.  Run the emulator.
2. Copy the apk file to /tools folder
3. Change directory to /tools and run from commandline  adb install your_application.apk [ this command for windows if you are using linux then  $install your_application.apk ]
4. Now check applications list in the emulator the new application installed and ready.

%d bloggers like this: