Thursday, March 21, 2013

Custom GridView in Android

Here, I am going to develop an application that displays icon with text as grid view.  In previous example, I showed you to create grid view with icons. In that case, only one xml is used to display the images. In case of custom grid view, you need to create two xml one for gridview and other for icon and text. After that we can inflate these two xml on your activity to create custom grid view

package com.example;

import java.util.ArrayList;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomGridViewActivity extends Activity {
    private ArrayList<String> textfield;
      private ArrayList<Integer> imagefield;
      private CustomAdapter customadapter;
      /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        GridView gridView=(GridView)findViewById(;
        customadapternew CustomAdapter(thistextfield,imagefield);
    public void preparetext()
        textfield=new ArrayList<String>();
    public void prepareimage()
        imagefield=new ArrayList<Integer>();
    private class CustomAdapter extends ArrayAdapter<Object>
            Activity activity;
            ArrayList<String> textfield;
            ArrayList<Integer> imagefield;
     public CustomAdapter(Activity context, ArrayList<String> name,ArrayList<Integer> image)
             super(context, 0);
  public View getView(int position, View convertView, ViewGroup parent)
            ImageView imgViewFlag;
            TextView txtViewTitle;
            LayoutInflater inflator = activity.getLayoutInflater();
            convertView = inflator.inflate(R.layout.gridviewnull);
            txtViewTitle = (TextView) convertView.findViewById(;
           imgViewFlag = (ImageView) convertView.findViewById(;
           return convertView;

    public int getCount() {
      // TODO Auto-generated method stub
        return textfield.size();

    public String getItem(int position) {
        // TODO Auto-generated method stub
        return textfield.get(position);

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;



<?xml version="1.0" encoding="utf-8"?>

Saturday, March 16, 2013

Edit spreadsheets on the go with the Drive mobile app

You’re making your list, you’re checking it twice -- and now you can do it from anywhere.

Just in time for this year’s holiday season, you can edit Google Sheets on your mobile device, just like you can with Google Docs. From the Drive app on your Android device, you can create a new spreadsheet or edit an existing one. You can switch fonts, resize columns, sort data, and more. And just like on your computer, you’ll be able to see other people’s edits in real time as they’re made.

Beyond spreadsheets, you may notice a few other tweaks to the Drive app, including better text formatting when you paste from one Google document to another. And from your Android device, you can edit text within tables in documents and add a shortcut on the homescreen of your device to any specific file in Drive. 

Whether it’s holiday recipes, shopping lists, or just your family budget, the Drive app on your mobile device makes it easy to get stuff done wherever you are.

Celebrating Google Play’s first birthday

Accessing digital entertainment should be simple, whether you like to read books on your tablet, listen to music on your phone and computer, or watch movies on all three. That’s why one year ago today we launched Google Play, where you can find and enjoy your favorite music, movies, books and apps on your Android phone and tablet, or on the web.

Google Play has grown rapidly in the last year, bringing you more content in more languages and places around the globe. In addition to offering more than 700,000 apps and games, we’ve partnered with all of the major music companies, movie studios and publishers to bring you the music, movies, TV shows, books and magazines you love. And we’ve added more ways for you to buy them, including paying through your phone bill and gift cards, which we're beginning to roll out in the U.K. this week.

Since no birthday is complete without presents, we’re celebrating with a bunch of special offers across the store on songs, TV shows, movies and books. We’re even offering a collection of games with some fun birthday surprises created by developers.

It’s been a busy year, but we’re just getting started. We look forward to many more years of bringing you the best in entertainment! 

Android and its Fragmentation

Android has been making rapid strides into the Mobile market and has become a serious contender for the top 1 position in the mobile market (and is picking up on the tablet market quite quickly).

The fact that it was anopen platform allowing for lot of innovation and choice made the developer world and the mobile OEMs vouch for it and the inroads it madeinto the market was significant – significant enough for Apple to stand up, take note and even file a law suit J

However, this very fact is now slowly turning to be a bane for the Android platform, as it has led to a huge amount of fragmentation in the market. OpenSignalMaps has done a research in 195 countries and has come up with the graphic that clearly depicts the kind of fragmentation in Android devices.

Samsung has clearly take a lion share of the market followed by HTC, Sony Ericcson and Motorola. An interesting fact is that they have spotted 3997 distinct devices!

This very fact has brought down the euphoria around Android. Another study by Appcelerator and International Data Corporation (IDC) says:

The most significant finding in the Q2 2012 Developer Survey is Apple opening a dramatic 16% lead over Google’s Android as far as which OS will win in the enterprise marketplace, with 53.2% of developers saying iOS will win vs. 37.5% saying Android will win. This is a very significant change over only three quarters: in Q3 2011, developers viewed iOS and Android in a dead heat at 44% each.
The challenges of this fragmentation are around the varied screen sizes and the many OS versions which translate to the larger effort and investment into testing on the varied combinations to keep all customers happy.
A graphic that illustrates the varied resolutions:
and the number of device models:

The above statistics sound a bit unsettling around the fragmentation aspects of Android and would probably scare away developers from investing on this platform!
But in my opinion, this is no different from the fragmentation on PC (probably better than that) where the browsers, the CPU powers, the models etc. are varied and still we have lot of gaming apps that are developed for all of them.
Probably the good news is that Android right from the beginning is learning its lessons quickly and it introduced the concept of “fragments” to scale to varied screen sizes and designs.
Android is just going through the stabilization phase of a open platform and the good news from the same study by Appelerator and IDC says:
Android has arrested its decline in developer interest. After a noticeable erosion of developer interest over the last year, developers’ Android handset “very interested” levels stabilized in Q2 2012 compared to Q1 2012, and Android tablet “very interested” levels ticked up 2.9%.

So, in my opinion, Android with all its challenges is just grown over the hype cycle and is here to stay as a strong contender to other mobile OSes and would probably win the race. However, right from the beginning, developers have to keep these variations in mind and build apps that look as seamless as possible on multiple OSes.
And testers, if you are reading, here is your chance... A lot of opportunities around device coverage, OS version coverage, screen size coverage and so on.

In Depth : Android Boot Sequence / Process

What happened when I press power on button in my Android device ?
What is Android boot sequence ?
What is linux kernel ?
What is different between desktop linux kernel and Android linux kernel ?
What is bootloader ?
What is Zygote ?
What is x86 and ARM linux ?
What is init.rc ?
What is System Server ?
Many questions pop-up in mind when we think about Android boot sequence.Here I am explaining Android boot process. I hope you will find answer of above questions.
Android is linux based open source operating system, x86 (x86 is a series of computer microprocessor instruction set architectures based on the Intel 8086 CPU.) is most likely system where linux kernel is deployed however all Android devices are running on ARM process (ARM (formerly Advanced RISC Machine, which was formerly Acorn RISC Machine)) except Intel’s Xolo device ( Xolo comes with Atom 1.6 GHz x86 processor. Android boot sequence or I can say embedded device or ARM based linux has minor difference compare to desktop version.  In this article I am going to explain boot sequence for Android only. Inside the linux boot process is good article for desktop based linux boot sequence.
Android device execute following steps when you press power switch
Android Boot Process
Android Boot Sequence / Process
 Step 1 : Power On and System Startup
When power start Boot ROM code start execution from pre defined location which is hardwired on ROM. It load Bootloader into RAM and start execution
Step 2 : Bootloader
Bootloader is small program which runs before Android operating system running. Bootloader is first program to run so It is specific for board and processor. Device manufacturer either use popular bootloaders like redboot,ubootqi bootloader or they develop own bootloaders, It’s not part of Android Operating System. bootloader is the place where OEMs and Carriers put there locks and restrictions.
Bootloader perform execution in two stages, first stage It to detect external RAM and load program which helps in second stage, In second stage bootloader setup network, memory, etc. which requires to run kernel, bootloader is able to provide configuration parameters or inputs to the kernel for specific purpose.
Android bootloader can be found at
<Android Source>\bootable\bootloader\legacy\usbloaderlegacy loader contain two important files that need to address here.
1. init.s – Initializes stacks, zeros the BSS segments, call _main() in main.c
2. main.c – Initializes hardware (clocks, board, keypad, console), creates Linux tags
Step 3: Kernel
Android kernel start similar way as desktop linux kernel starts, as kernel launch it start setup cache, protected memory, scheduling, loads drivers. When kernel finish system setup first thing it look for “init” in system files and launch root process or first process of system.
Step 4: init process
init it very first process, we can say it is root process or grandmother of all processes. init process has two responsibilities 1. mount directories like /sys, /dev, /proc and 2. run init.rc script.
  • init process can be found at init : <android source>/system/core/init
  • init.rc file can be found in source tree at <android source>/system/core/rootdir/init.rc
  • readme.txt file can be found in source tree at <andorid source>/system/core/init/readme.txt
Android has specific format and rules for init.rc files. In Android we call it as “Android Init Language”
The Android Init Language consists of four broad classes of statements,which are Actions, Commands, Services, and Options.
Action : Actions are named sequences of commands.  Actions have a trigger which is used to determine when the action should occur.
on <trigger>
Service :  Services are programs which init launches and (optionally) restarts when they exit.  Syntax
service <name> <pathname> [ <argument> ]*
Options : Options are modifiers to services.  They affect how and when init runs the service.
Let’s take a look of default init.rc file. Here I have listed only major events and services.
Action / ServiceDescription
on early-initSet init and its forked children’s oom_adj.
Set the security context for the init process.
on initsetup the global environment
Create cgroup mount point for cpu accounting
and many
on fsmount mtd partitions
on post-fschange permissions of system directories
on post-fs-datachange permission of /data folders and sub folders
on bootbasic network init ,Memory Management ,etc
service servicemanagerstart system manager to manage all native services like location, audio, shared preference etc..
service zygotestart zygote as app_process
At this stage you can see “Android” logo on device screen.
Step 5: Zygote and Dalvik
In a Java, We know that separate Virtual Machine(VMs) instance will popup in memory for separate per app, In case of Android app should launch as quick as possible, If Android os launch different instance of Dalvik VM for every app then it consume lots of memory and time. so, to overcome this problem Android OS as system named “Zygote”. Zygote enable shared code across Dalvik VM, lower memory footprint and minimal startup time. Zygote is a VM process that starts at system boot time as we know in previous step. Zygote preloads and initialize core library classes.  Normally there core classes are read-only and part of Android SDK or Core frameworks. In Java VM each instance has it’s own copy of core library class files and heap objects.

Zygote loading process
1. Load ZygoteInit class,
Source Code :<Android Source> /frameworks/base/core/java/com/android/internal/os/
2. registerZygoteSocket() –  Registers a server socket for zygote command connections
3. preloadClasses() – “preloaded-classes” is simple text file contains list of classes that need to be preloaded, you cna find “preloaded-classes” file at <Android Source>/frameworks/base
4. preloadResources() – preloadReaources means native themes and layouts, everything that include android.R file will be load using this method.
At this time you can see bootanimation
Step 6: System  Service or Services
After complete above steps, runtime request Zygote to launch system servers. System Servers are written in native and java both, System servers we can consider as process, The same system server is available as System Services in Android SDK. System server contain all system services.

Zygote fork new process to launch system services. You can find source code in ZygoteInit class and “startSystemServer” method.

Core Services:
1.     Starting Power Manager
2.     Creating Activity Manager
3.     Starting Telephony Registry
4.     Starting Package Manager
5.     Set Activity Manager Service as System Process
6.     Starting Context Manager
7.     Starting System Context Providers
8.     Starting Battery Service
9.     Starting Alarm Manager
10.   Starting Sensor Service
11.   Starting Window Manager
12.   Starting Bluetooth Service
13.   Starting Mount Service

Other services
1.    Starting Status Bar Service
2.     Starting Hardware Service
3.     Starting NetStat Service
4.     Starting Connectivity Service
5.     Starting Notification Manager
6.     Starting DeviceStorageMonitor Service
7.     Starting Location Manager
8.     Starting Search Service
9.     Starting Clipboard Service
10.   Starting Checkin Service
11.   Starting Wallpaper Service
12.   Starting Audio Service
13.   Starting HeadsetObserver
14.   Starting AdbSettingsObserver
Step 7 : Boot Completed
Once System Services up and running in memory, Android has completed booting process, At this time “ACTION_BOOT_COMPLETED” standard broadcast action will fire.