Android AJAX Auto Load

What is Ajax Auto Load?

If you take a look at dynamic websites, the content of the website will be refreshed automatically without user intervention. Example โ€“ CricInfo in which the score card will be refreshed in a time interval and display the latest score.

AJAX Auto Load in Android

The Android application which we are going to develop will refresh the content of activity and show the latest content retrieved from the server through AJAX call. Our application gonna get the server’s time through AJAX call for every 5 seconds and update the server time inside Android activity. This will happen without user intervention (like Tap, Scroll, Click etc.,).

Interesting? Let’s us start create the application.

I would recommend you to take a look at AJAX Tutorial before we start developing the application as it will give you an idea about AJAX Auto Load.


As this application requires Internet connectivity, we need to check if Internet connectivity is available or not.

Here are the tutorials which talk about checking Wifi/Mobile Internet:

Android Check Wi-Fi Internet Connection
Android Check Mobile Internet Connection

Quick Links

Project Structure

Create layout XML

  • Create new android project [File >> New >> Android Project] with project name AndroidAJAXAutoLoad
  • Click next and select target android device version [I chose version 2.2]
  • Click next and enter package name – ‘’
  • Click finish

Code Listings

Open main.xml, now you can view the layout as either XML or in graphical view and just replace the XML with below one:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="@string/content" android:gravity="center"/>

        android:layout_height="306dp" />

Here is MainActivity code. Each line is explained with comment:

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.webkit.WebView;

public class MainActivity extends Activity {
	 WebView browser;
    public void onCreate(Bundle savedInstanceState) {
        //Refer WebView
        //Enable Javascript
        //Set font size to 20
        //Load the URL



Let us test the application:
Run click on the project >> Run as >> Android application
You could see following screen:

Download Source Code

Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project(How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.

Download Source Code Download Application(apk)

*apk in Android is the installation file simliar to exe in windows.


I hope you enjoyed the post!! ๐Ÿ™‚
Keep us posted with your valuable comments below ๐Ÿ™‚


Related Articles

Author: Udhay

Share This Post On
468 ad
Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest