Saturday, December 17, 2011

Android Application Performance Improvement (using DDMS-Traceview/MAT tool): Part-1

The Application Performance improvement process is one of the real challenges in the mobile application development. Android provides various tools to analyze the performance of the application, like-DDMS, Traceview, Allocation Tracker. The memory analysis can be done through Eclipse Memory Analysis Tool which a very powerful tool. It provides various analysis, like-Histogram, Dominator Tree, Leak Suspects along with chart analysis.

This post covers the time analysis of an application, i.e. Stock Watch Application (which is one of my in-house developments) for an example, by using Traceview tool and the improvements observed in the application performance on post-optimization.

Traceview


Traceview is a graphical viewer for execution logs that you creates by using the Debug class to log tracing information in your code. Traceview can help you debug your application and profile its performance. It displays the log files data in two panels:
  • A timeline panel -- describes when each thread and method started and stopped
  • A profile panel -- provides a summary of what happened inside a method

Traceview Analysis on Pre-optimisation

Traceview helps us to find out the time spent in each method so that we could track the performance of each method we have written in the application.

1.       Start with Traceview profiling: Open Eclipse->DDMS->Devices(Tab), select the process of your application in the all the processes running on emulator/device. Now press ‘Start Method Profiling’ button as shown in below image.


2.       Application Navigation: Navigate to the application parts for which you want to create the profiling

3.       Stop Profiling: From the Devices Tab, select ‘Stop Method Profiling’ button as shown in below image. A profiling report will get generate automatically where you can start analysis.



As shown in the below image of Traceview report, the navigation time of these two activities is 51000 milliseconds*. The control was in the main Asynchronous thread for a large amount of time.

*since it is tested at android emulator; on device we might found the time difference.


Traceview Analysis on Post-optimisation

After optimizing the code, the navigation time has been reduced from 51000 milliseconds to 42000 milliseconds.


Performance Improvements
Improving application performance in terms of time and memory is one of the real challenges in mobile development. The android native tools like-DDMS/Traceview plays a significant role in improving the performance. Also these performance tests can be executed during the development life cycle.

Following are the performance improvements by using both the tools:

v  Using Traceview:
·         Navigation time reduced by 18%

·         Time spent by program control in Asyn Thread is lessened.

Hope now you can take advantage of Traceview tool to improve the performance of your application.

Note: The later parts of this post will cover the other tools analysis to improve android app performance. Keep an eye!! J

Thursday, December 15, 2011

Deploying the Application on the Device (Mac or Windows or Linux)


The application is deployed to the Emulator directly from the Eclipse. To deploy the application on the Android powered device, following are the steps:

Declare Application as ‘debuggable’

We will declare our application as ‘debuggable’ in Android Manifest.xml file shown in Fig.1 at position 6 by adding android: debuggable="true" to the <application> element.

Android Device Setup

We will turn on the ‘USB Debugging’ on the device

·      On the device, go to home screen, press MENU then select Application->Development
·      Enable ‘USB Debugging’

System Setup to detect the device

This step varies for different operating systems on which we are developing our application.

Windows

Install a USB driver for adb (Android debug Bridge)

Mac OS

For Mac OS X, skip this step as it works fine.

Ubuntu Linux

In case of Ubuntu Linux, we need to add a rules file that contains a USB configuration for the device (Vendor Id) which we are using for development.

·      Log in as root and create this file: /etc/udev/rules.d/51-android.rules
§  For Gusty/Hardy, edit the file to read:
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"

§  For Dapper, edit the file to read:
SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0bb4", MODE="0666"

·         Now execute:
chmod a+r /etc/udev/rules.d/51-android.rules

Run the Application

If you are using Eclipse, then select Eclipse->Run->Run Configurations->Run, in the available Device Chooser dialog that lists the available emulators and connected devices, select the device and click Run

If you are using command line, then open the cmd window and run the following command to run the application
C:\[path_to_adb_tool] > adb install [path_to_apk]\ [appname].apk

Enjoy your application watching at your mobile J

Wednesday, December 14, 2011

How to create Android Application?


The Android SDK provides the tools and APIs necessary to develop applications on the Android platform using the Java programming language. To start with Android application development, the developer needs to have elementary knowledge of Java and XML.
Well, starting with the creation of first android application,
a)    Select Eclipse->File->New->Android Project, in the dialog, fill the fields, Project Name (ex: MyFirstApp), Build  Target (to compile the application by a particular Android SDK), Application Name (name of application, ex:      MyFirstApp), Package Name (ex: com.myapp), Create Activity (ex: MyFirstActivity)
   b)       Click on Next->Finish. An android project folder with
           Name ‘MyFirstApp’ will get built in the left pane (Project Explorer) of Eclipse.
   c)       On exploring the Project folder, you will be able to see the sub folders /src, /gen, /res & AndroidManifest.xml as shown in the below image at positions 1, 2, 4 and 6 respectively.




There are four building blocks to build an Android Application- Activity file, R.java, Resource files and Android Manifest file as shown in above image at positions 1, 3, 4, 6 respectively. Activity files are used to write the Business logic of action happening on the Android Screen. The resource files are used to create the layouts for the screen. The Android Manifest file presents the essential information about the application to the Android OS, like- version, icon, activities and permissions given to application, which Android requires before running any application. R.java file does the mapping between layout files and Activity file.


Activity File

  • Edit MyFirstActivity.java in the package com.myapp (at position 1) as the code shown in the above image.
  • Next, the Emulator is required to see the output screen. Following are the steps to create emulator:
  • Select Eclipse->Window->Android SDK and AVD Manager. In the available dialog, select Virtual devices >New.
  • In the available dialog, enter the name of emulator (ex: MyDevice) and select the target API (Android version)for the emulator. Now click on Create AVD button.
  • The emulator with name ‘MyDevice’ will be added in the list of existing emulators (if any) on the previous dialog and to start the emulator select Start from the dialog.
  • To run the application, select Eclipse->Run->Run Configurations.
  • In the available dialog click on Run and see the log in the console window of the Eclipse.
The eclipse itself installs the application on the Android Emulator and the output can be seen in the Android Emulator as shown in the below image.
Output screen on Android Emulator


Tuesday, December 13, 2011

Android Development Environment Setup


This post is for new Android Developers or for those who have little interest in android development and wanna see the android li’l closely J

Here are the crisp steps to setup the android development environment!!

The developers are able to setup Android development environment by using Netbeans or Eclipse IDE and also by using command line tools (Apache Ant). But, Eclipse IDE is the Android development environment recommended by Google. The Android Development Tools (ADT) is a plugin for the Eclipse IDE designed to give a powerful, integrated environment to build Android applications.

Android ADT plugin extends the functionalities of Eclipse and set up the Android projects quickly and create application UI, add components based on the Android Framework API, debug application using DDMS tool and export the apk (Android Package) file to the emulator.

Android Development Environment Set up Using Eclipse

a)    Install JDK: Download and install JDK 5 or JDK 6 from http://java.sun.com/javase/downloads.

b)    Install Eclipse IDE: Download Eclipse Classic 3.5.1(or higher) https://www.eclipse.org/downloads/ and unzip it into the disk (in any folder).

c)    Download ADT Plugin: Download the latest version of Android ADT plugin for Eclipse http://developer.android.com/sdk/eclipse-adt.html and save it as a zip file into the disk (in any folder).

d)    Download Android SDK starter package: Download the Android SDK pack .zip archive according to the operating system of development computer (Windows/Linux i386/Mac OS X) http://developer.android.com/sdk/index.html and unpack it into the disk (in any folder). By default, the SDK files are unpacked into a directory named android-sdk-<machine-platform>.

e)    Configure ADT plugin with Eclipse:  Android offers a custom plugin for the Eclipse IDE, Android Development Tools (ADT).  Following the steps to configure it with the Eclipse.

·         Select Eclipse->Help->Install New Software, in the available dialog Select Add and enter the name of plugin (ex: “Android Plugin”) in the Name field and locate the ADT plugin zip file after selecting on Archive.

·         Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools and then click Next.

·         On the next dialog, click Next to read and accept the license agreement and install any dependencies, then click Finish.

·         Restart Eclipse.

f)    Configure Android SDK Starter Package: Select Eclipse->Window->Preferences, in the available dialog, select Android from the left panel and in the right panel of the dialog, click on Browse to locate the Android SDK root directory named as android-sdk-<machine-platform> and click on Apply and OK.

g)    Adding SDK Platforms for different Android OS versions and samples: Select Eclipse->Window->Android SDK and AVD Manager. Now in available dialog, select Available Packages and install the latest version of the SDK.

Exploring the SDK directory (optional): On exploring the SDK directory, the contents inside the root directory are add-on/, docs/, platform-tools/, platforms/, samples/, tools/, SDK Readme.txt, SDkManager.txt
Enjoy coding for android :)

Sunday, December 11, 2011

Android Solutions

Hi guys!!

I am starting this blog as an Android Developer who is doing little R&D on application development level. I'd like to ensure you that lots of posts are in pipeline to come on the blog which will resolve many of common & severe issues during android development, new adventures and feature exploration in android.

Note: You can post your random questions related to Android App Development, which will be responded at the earliest.

Thanks!!

Proxy Settings in Android Emulator (For Corporate Network) to access internet


If you are sitting behind a proxy (like- corporate network or any other), you need to do the proxy settings to access the internet in Android Emulator browser by the following steps:
  1. Get the Proxy Host Address and port number of your network
  2. Open the Menu->settings->Wireless & Networks->Mobile Networks->Access Point Names in Android Emulator
  3. Open Telkila
  4. Edit Proxy to your Proxy Host Address like-10.117.123.169
  5. Edit Port to the your Port like-8080
  6. Remove * from UsernamePassword and Server fields and make them blank(<not set>).
  7. Set Authentication Type as “PAP or CHAP”
  8. Now, Press Menu->Save

Well done!! Now your emulator is ready to receive the web packets J Launch the Browser and test it.