Introduction

Most of the tutorials starts with "Hello World" applications for beginners to start with. In this article, I have jumped a step forward to come up with a bundle of tutorials which I hope will be useful for Android developers (beginners) to start with.

The application is a simple Job Search. From an Android phone, the user can search for jobs in a Job website (ASP.NET website) based on user current location (using GPS) and Job Location. The user will enter the search keyword and the number of miles and he will get all the jobs within the distance he entered based on his current location.

The application will cover the following tutorials:

Creating splash screen using thread and wait command

Navigating between different screens and using Android navigation menu

Using GPS to get current location

Communicating with .NET web service using ksoap library

Listing the records in a table with functionality to click each row

Passing parameters between various screens

Displaying Google Map

Tools and IDEs

Here are the tools and IDEs used to develop the above application:

Android SKD: Development kit for Android including emulator. Download from here.

Eclipse: A JavaScript Development IDE

Visual Studio 2010: .NET to develop the web service

Server Side Code

First of all, let me explain the hosted web service with the database table that contains the Jobs Adverts records. Below are the records we have added in the "Jobs" table.

Note that we have added the "Latitude" and "Longitude" values for each job. This will be compared with the current location from the GPS and calculate the distance in miles.

I have a function in SQL Server that will calculate the distance in miles between two Geo Points (Latitude, Longitude). See the code below:

Next, I have a .NET web service hosted in the localhost with a web method "JobSearch". The web method will accept Search keyword, number of miles, current latitude value and current longitude value from the user and it will query the database to get the results. The above function is used in the query to calculate the distance.

Client Side Code

Assuming that Eclipse and Android SKD are already installed and configured, for more information, click here.

I have started my application with a splash screen. It is just the first screen that contains the application name logo, will be displayed for around 5 seconds and will navigate to the main application screen.

Next, is the "Home" screen, which is just containing three buttons and three lables for just building the menu.

Note: Here, I am not focusing on laying out components in Android, I am assuming the developer already knows how to build layout. For more information about Android layouts, see Understanding User Interface in Android.

Just a quick look, the below code is showing how to attach click event to a button.

Alternatively, you could utilize the Android Menu to build up your menu system. In this case, you will need to press the "Menu" button in your phone in order to display the menu and it will be displayed in the bottom of your phone screen.

In the same screen "Home", I have GPS functionality to sense the current location of the user. For this functionality, I have created a new class that implements the "LocationListener", so each time the GPS senses a new location, this callback function will be called from the Android system.

We will add our own personal Location listener, and override the mandatory functions. In our case, we will just print a message to the screen in the following cases:

onLocationChanged (Location Update)

onProviderDisabled (GPS Off)

onProviderEnabled (GPS On)

And add another mandatory method, which will do nothing: onStatusChanged (We are not adding anything here).

To simulate a location update, we need to connect to the simulator by telnet, and do the following:

telnet localhost 5554
geo fix 30 28

You should get these results:

Connecting to the Web service

Next, is the "Job Search" screen which contains two TextBoxes and a Search Button. The user in this screen will enter the Search Keyword and the Distance in Miles and click search to query the jobs records from the web service.

Note: If you need to refer to your host computer's localhost, such as when you want the emulator client to contact a server running on the same host, use the alias 10.0.2.2 to refer to the host computer's loopback interface. From the emulator's perspective, localhost (127.0.0.1) refers to its own loopback interface. That's why I have the Web Service URL as:

Next, in the "Job Details" screen, we will need to read the parameters passed from the previous screen. To do that, we need to add the following code in the "OnCreate":

Intent i = super.getIntent();
//get all parameters passed from previous screen
Bundle bun = i.getExtras();
//get the parameter by name
String JobID = bun.getString("JobID");
//this will again connect to the web service and get the job details by id.
PopulateJob(JobID);

Show the Job Location in the MAP

When the user clicks on the job to see the job details, he have the option to view the job location in the MAP. I have used Google MAP library for Android. Note: You will need to have Google API Key.

i have developed an application similar with what you have posted here, but i am not sure what connection string should i put in the web.config of the .netwebservice?
Could you give me some explanations about that please?
Thank you!

is it just the emulator or the app is already installed in the android phone? and then the phone can connect to my localhost through the use soap library???how come is it possible that an android app can access the asp.net site without an interet connection ????