Category Archives: Android

Android ListView and ArrayIndexOutOfBoundsException

While working on an app with a native Navigation Drawer, I noticed that on Android 4.0.4 my app crashes. I could not get this exception on any other version of Android.

1
2
3
4
5
6
    java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
    at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:5996)
    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4554)
    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3874)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)

After spending about an hour trying to figure this out, I realized that my Adapter for the List View returned a value of 2 from the getViewTypeCount() method, and getItemViewType() returned a value of 1, or 2, depending on the type of view. The getItemViewType() is suppose to start with a value of 0, so it should be returning a value of 0 or 1, instead.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class ActionBarDrawerAdapter extends BaseAdapter {
    ...
    @Override   
    public int getViewTypeCount() {
        return 2;
    }
 
    @Override
    public int getItemViewType(int position) {
        ActionBarDrawerItem item = (ActionBarDrawerItem) getItem(position);
        if (item.isSubnavItem()) {
            return 1;
        } else {
            return 0;
        }
    }
}
Share:

Adding kSOAP 2 to your Android Gradle project

I am working on an app that needs to communicate with a server using SOAP messages. I decided to use the kSOAP2-Android library, since is seems to be the most robust way to handle SOAP calls in Android.

To add the library as a dependency to your project, download the kSOAP2-Android JAR file into the libs directory in the project. (At the time of writing this, version 3.0 were the most current version)

Open the Gradle build file (gradle.build) and add the kSOAP dependency (your dependencies block should look something like this)

dependencies {
    ...
    compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
}

Now all you need to do is to clean the project.  That can be done from the command line, or from the Android Studio IDE.  From the command line, in your project directory, run “./gradlew clean”, then rebuild and run your app.

Share:
Screen Shot 2013-01-17 at 10.46.49 AM

Installing and Configuring the Google TV Emulator

The Google TV developers released a GoogleTV add-on for the Android SDK that makes emulation possible on the Windows and Mac Operating Systems (Linux was already supported).

Assuming that you have the Android SDK already installed:

In order to use the emulator, you need to open the Android SDK Manager and make sure that you have the “Google TV Addon” [under Android 3.2 (API 13)] and the “Intel Atom x86 System Image” [under Android 2.3.3 (API 10)].

 

If you installed the “Intel Atom x86 System Image”, you need to install the “Intel Hardware Accelerated Execution Manager” which can be found in the <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/
directory.  
For Windows, install the IntelHAXM.exe file.  
For Mac, install the IntelHAXM.dmg file.
You can read the installation instructions here http://developer.android.com/tools/devices/emulator.html

Create a new “Device Definition” in the “Android Virtual Device Manager” using the configuration below.  
For 1080p use a resolution of 1920×1080 and a density of xhdpi.
For 720p use a resolution of 1080×720 with a density of tvdpi.

 

Then create a “Android Virtual Device” using the “Device Definition” that you just configured.

 

Share:
Google TV Logo

What is Google TV

What is Google TV?
Google TV is an Android based platform that brings live TV, web and android apps all together in one device. It is like having a computer, cell phone, and television all in one.

Why develop for Google TV?
Did you know that the average person watches 5 hours of television every day? Due to this large amount of TV watching about 20% of televisions sold in 2010 were internet ready. Having this Google TV platform gives you the ability to develop apps that will enhance the TV viewing experience for millions of viewers. For example an app focused on sports can bring the most up to date statistics, video content and game scores to each viewer on personal demand.

Does developing for Google TV intrigue you? Well if it does then my next post will take you through the steps of how to get your Google TV development experience started.

Share:

Unlock and Root your Nexus One with Android 2.3.4

I recently received a Nexus One phone and did all of the updates almost immediately. What I did not realize was that the phone does not have root by default, so I started searching to see if I can root a Nexus One running Gingerbread (Android 2.3.4). I found a lot of older information, and some pretty tedious methods, involving downgrades.

I then found a way to unlock the Bootloader on the Nexus One, and got root!

This is what I did:
Unlocking the Bootloader 1

  1. Install the Android SDK.
  2. Power off the device, and then power it back on, while holding the trackball. This will get you into bootloader mode.
  3. Connect the phone to your computer.
  4. Download and Extract fastboot
  5. Go to your command prompt/terminal and run the fastboot file from where you extracted it to:
    • Windows: Type ‘fastboot-windows oem unlock’
    • Linux: Type ‘./fastboot-linux oem unlock’
    • Mac: ‘./fastboot-mac oem unlock’

    This should pop up a message on your device asking you to verify that you want to unlock the bootloader. With the volume +/- go to YES and press the power button.

Rooting the Phone and installing a Recovery Image 2

  1. Download and add su.zip to your SD Card.
  2. Download fastboot and unzip it.
  3. Download the recovery image and place it in the same directory where you unzipped fastboot.
  4. Power off the device, and then power it back on, while holding the trackball. This will get you into bootloader mode.
  5. Connect the phone to your computer.
  6. Go to your command prompt/terminal and run the following commands in the directory where you unzipped fastboot:
    1. fastboot devices
    2. fastboot flash recovery recovery-RA-passion-v2.2.1.img
  7. With the volume +/- buttons on the phone, move to “Bootloader” and press the power button.
  8. Again, with the volume +/- buttons, move to “Recovery” and press the power button.
  9. Use the trackball and move down to “Flash zip from SD Card”, and press the trackball to select.
  10. Select su.zip (you copied this in step 1) and press the trackball to select.
  11. When this is done, go ahead and reset the phone, you should now have root. You can verify this with the “Root Check” app, available from the market.
Share:

Notes:

  1. http://android.modaco.com/topic/299078-how-to-unlock-the-bootloader-on-your-nexus-one/
  2. http://chensun.net/android-development/root-nexus-one-with-android-2-3-3-gingerbread/8/