Installing and configuring Android SDK outside IDE

I have always configured and used Android SDK from Eclipse. In fact, ADT (Android Development Kit) bundle now comes with Eclipse IDE pre-configured for Android development.  This makes using the SDK very easy. Options like configuring SDK manager and virtual device manager are available right from Eclipse menu.

However, I had a requirement where I wanted to run only Android emulator and not IDE. The Android SDK site has all the information to do this, but not in one easy to find place. So I thought I will write about it, for my own reference.

Continue reading “Installing and configuring Android SDK outside IDE”

Starting Android Activity on device restart

I finally got around to fixing a bug in my Android application, Simple Task Reminder, which was on my to-do list for a long time.The issue was that all reminders set in this application were lost on device restart. The solution was to set reminders again after device rebooted.

Android SDK provides a mechanism to receive notification for your application, after the device is booted. You need to add a broadcast receiver in the manifest file –
Continue reading “Starting Android Activity on device restart”

File Chooser Dialog for PhoneGap Applications

I needed a file chooser dialog box for an application I am working on. Android APIs do not have File Chooser dialog, and I had created my own native Android File Chooser dialog for my application Annotated Call Log. However I did not want to use that for my current application, because it needs to run on iOS too.

A quick search on the Web for PhoneGap based file chooser dialog did not give me what I was looking for, so I decided to create one using PhoneGap file APIs, JQuery and JQuery Mobile. You can find the source code here. The page won’t display much in the browser. Use ‘View Source’ of your browser to see the source code.
Continue reading “File Chooser Dialog for PhoneGap Applications”

Improving Animation Performance in HTML5 Canvas

I have been working on an application that performs some animation in HTML5 Canvas. The animation involves drawing of stokes,images and moving images. Initially I took the easiest path for coding animation, which is clearing canvas every time and drawing new positions of objects. When tested this application on my laptop, in Chrome, everything worked fine and performance was satisfactory.

However when I ran the same application on my Xoom tablet, animation was extremely slow. Obviously clearing canvas and redrawing everything again and again was not a good idea. I did know that this approach was bad for animation, but since it worked fine on my laptop, I did not bother to change it initially. However I was surprised by how bad it performed on Android. I saw many complaints about performance of Canvas on Android in many forum posts and blogs. Apparently, as per many posts, performance of Canvas is much better on iOS than Android, but I can’t confirm this.
Continue reading “Improving Animation Performance in HTML5 Canvas”

Android Gotcha – Application Lifecycle Management

This week I was hit by another bug because of not considering impact of Android’s application life cycle management. Last week I had blogged about unexpected behaviour because of using static members in Activity class. The new bug (in another application) was not the same, but it was caused by Android’s application lifecycle management. To be clear, I am not saying there is any problem with the way Android handles application lifecycle.

A user of my application ‘Annotated Call Log’ informed me that when the call duration was very long (more than 45 minutes), the application sometimes did not save call information. The way this application works is – it has a broadcast receiver for getting call status. When a call begins, this class receives notification and it saves call information like phone number, call start time etc in member variables. When the call ends, the receiver class is again called and it then saves call information in the database.
Continue reading “Android Gotcha – Application Lifecycle Management”

Creating Android Applications with HTML User Interface

I created my first two Android applications completely using Android APIs. However I realized that I can build better user interface quickly using HTML, JavaScript and CSS. Android SDK provides WebView controls which is a browser control. So I started looking for ways to make WebView render local HTML files. Most APIs of WebView are simple to understand and use, except one important method, loadUrl.

To begin with I was not sure where to store my HTML/JS files in the Android project and what URL to use to load them. JavaDoc help for WebView did not mention how to load local assets into WebView. It turned out that you need to keep all your HTML/JS files in the ‘assets’ folder of you project and load them with URL file://android_asset/.
Continue reading “Creating Android Applications with HTML User Interface”

Android Activity class and static members

In one of my Android application, I was storing some data in a static member variable. After few hours of inactivity, when I used to open the application, I would see that all the data I had stored in the static member variable was gone.

I know about the Android Activity life cycle and that Android can unload Activity class if it is not active. However I did not think that it would reset all static members too. So I had three options to persist data –

  1. Store it in preferences
  2. In a file (local or on external media)
  3. In the database
  4. In the Android application class

See this article for more details about data storage options in Android.  Since the data is not large and I did not already have Android database created for this app  (this app does use database, but it’s HTML5 database), I decided to use option #4. Storing in application class also suited this application because I do not need the data if Android or user kills the application.

So, be very careful when using static variables in Activity class.

-Ram Kulkarni

Social