Home » Android » How to Develop Android Apps

How to Develop Android Apps

As compared to iPhone OS, Android platform is better as the latter one is an open source and you can develop your own apps very easily and market them as well without any licences or approval.


If you have the right software installed in your PC,

you can code for Android app on your PC and can be tested using an Android emulator to check its behavior when it will be run in Smartphone. We’ll guide you how to write and run a basic ‘Hello world’ application in Android.

Pre-requisites

  1. Android apps are developed using Java code, so you need to install Java development kit in your PC.
  2. An integrated development environment (IDE) is required to write and test the code. e.g Eclipse IDE.
  3. Android Development Tools which is plugged in from the Eclipse IDE to work with.
  4. Android Software Development Kit, used to generate and execute suitable Java code within an Android emulator.
  5. At least one version of the Android platform. Once you’ve downloaded a version of Android, you also need to set up a virtual device to run in the emulator.

Stepping Forward

There are several steps you need to take to get your computer ready for the Android SDK. First, install a Java Development Kit. You can get the right one for your version of Windows from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

You also need to install Eclipse IDE for Java developers, which is available from http://www.eclipse.org/downloads.

When you install Eclipse, it will check for the JDK. It’s best to extract Eclipse in the same directory as the JDK. Eclipse won’t install if it can’t find it, but you can move the required files to whichever directory the Eclipse installer is examining.

Installing Android SDK

With Eclipse installed, you can download the Android SDK. Extract it to a safe directory and make a note of where it is. This can be done in the following way:

  1. Select ‘Save File’ and wait until the files get downloaded.android-sdk manager
  2. Run the Setup file which is already downloaded and press ‘Next’.sdk_manager_wizard
  3. If JDK is already installed in your system then nothing to worry and simply proceed with the next step otherwise you have to download it on clicking ‘Visit java.oracle.com’ and get it installed.sdk_tools_setup
  4. Click on ‘Next’ Button on the Android SDK installer. Remember one thing if you have installed JDK in step 3, then ‘Next’ Button will be in disable mode, for that you have to click on ‘Back’ button followed by ‘Next’ Button.
  5. Give the directory path where you want to install the Android SDK tools and Please do remember this path and directory name as this directory with full absolute path is required while configuring ADT Plugin in Eclipse IDE. In our case the directory name with absolute path is C:Program FilesAndroidandroid-sdk.sdk_tools_setup
  6. Press Next to proceed with further installation.
  7. Click on ‘Install’ Button in order to install and if you don’t want to create shortcut check the checkbox ‘Do not create shortcuts’.sdk_tools_setup
  8. Press ‘Next’ and if you want to run SDK Manager then check ‘Start SDK Manager’ checkbox else uncheck ‘Start SDK Manager’ and click ‘Finish’.

Installing the ADT Plugin for Eclipse

Back in Eclipse, you need to add the Android Development Tools.

  1. Navigate to ‘Menubar|Help | Install new software’.install_ADT_Plugin
  2. Next to ‘Work with’, enter https://dl-ssl.google.com/android/eclipse and click ‘Add’.
  3. Give proper name in the Name section ‘ADT Plugin’ in the ‘Add Repository’ pop up appeared once ‘Add’ is clicked.install_ADT_Plugin
  4. In the pane below this, check ‘Developer Tools’ and click ‘Next’.install_ADT_Plugin
  5. In the next window it will show the tools to be downloaded and click ‘Next’.install_ADT_Plugin
  6. Next in the license agreement window, Read and Accept the license agreement and click on ‘Finish’.install_ADT_Plugin
  7. Once all the tools get installed, Restart the Eclipse once prompted to restart.

Configuring the ADT Plugin

So far we have installed Android SDK tools and ADT plugin. Now we will configure the ADT Plugin the following steps:

  1. In Eclipse navigate to ‘Window | Preferences’.
  2. In the left panel, select Android.
  3. After that, Next to ‘SDK location’, click ‘Browse’ and find the folder containing the SDK. In our case it is C:Program FilesAndroidandroid-sdkconfigure_ADT_Plugin
  4. Click ‘Apply’ and ‘OK’.

Adding Android Platforms

To test any apps you create, you’ll need a version of the Android platform installed. You can do this using the following steps:

  1. Start Eclipse, navigate to Window → the Android SDK and AVD Manager.
  2. Select ‘Available Packages’ and tick the box next to ‘https://dl-ssl.google.com/android/repository/repository.xml’.android_platform
  3. After a scan of the repository, you’ll see the available components. Tick those that you want to install and clear the others(samples, if wished then Google APIs). Remember that the the latest version of the Android platform is the most important package to install and if you want to release your apps, then you are required to test your apps in variety of platforms.
  4. Click ‘Install accepted’ and wait for the components to be downloaded.android_platform
  5. Verify and accept the new components if prompted and these will be there in C:Program FilesAndroidandroid-sdk folder.

Setting up Android Virtual Device

Once you got at least one version of the Android platform installed, you need to set up an Android Virtual Device, or AVD and the same can be done in the following way:

  1. Choose ‘Window | Android SDK and AVD Manager’
  2. Select ‘Virtual Devices’.
  3. Click ‘New’ and provide a name for your new device.
  4. Select the Android platform that you want to use as the target.
  5. Click ‘Create AVD’.AVD_Manager
  6. Once finished, close the Android SDK and AVD Manager.

N.B:

  • Android Virtual Device changes with the change of Android Platform. If you want to test your apps in different platforms, you need to create new virtual device for the concerned android platform with other parameters here, including the presence and size of an SD card. A file can be selected to use as a virtual SD card, too.
  • Built-in skins with resolution specified are recommended to use.
  • Under ‘Hardware’, click ‘New’ to select a device in order to add more virtual hardware.

Creating New Android Project

If all software required are installed correctly, you can set up a new project in Eclipse to begin creating your application and can be done in the following way:

  1. In Eclipse IDE, navigate to ‘File | New | Project’.
  2. In the ‘New project’ wizard, select the ‘Android’ folder and choose ‘Android Project’. Click ‘Next’.Android_Project
  3. Once ‘Next’ is clicked, new window will appear for project details.
  4. Here we will set up a ‘Hello world’ application, which displays text when launched. Enter the followings details in the fields:
    • Project name : HelloAndroid
    • Application name : Hello, Android
    • Package name : com.example.helloandroid
    • CreateActivity : HelloAndroid.
    • Leave the other project fields at their default values.
  5. Click ‘Finish’.

Explanation of the Parameters

  • These parameters are required to set up your project in Eclipse. A directory(as the name of the ‘Project Name’)will be created in the Eclipse workspace, which will contain all the project files. e.g: ‘C:UsersusernameworkspaceHelloAndroid‘.If you navigate to this directory, you will find a number of subfolders and files created as per your project.
  • ‘Application name’ will be the title of your app, and will be displayed on the Android device.
  • ‘Package name’ is the namespace where all the source codes related to your project resides, so be careful with the package name and should be as per java package naming conventions and should be unique across Android System. e.g: com.example. If your developed apps get published then namespace conatins organisation name as well.
  • ‘Create activity’ relates to the class stub generated by the plug-in. An activity is basically an action.
  • ‘Min SDK version’ enables you to set the minimum API needed by your app.
  • If ‘Use default location’ is ticked, your project is saved in your workspace.
  • ‘Build target’ is the platform target for your application – the minimum version of Android it will run on. If you develop an app to run on an older version of Android platform, it should run on a later one too, but the reverse is not true. It is not so critical as long as you don’t run your apps run in the emulator.
  • Now you will be able to see the project in the Package Explorer and double-click ‘HelloAndroid’ to expand it.
  • Expand ‘src’ and ‘com.example.helloandroid’. Doubleclick ‘HelloAndroid.java’ to see the code that’s set up.
  • In the main pane, you will see this code

View Your Android Project

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super. onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }
}

If you are not able to see the above code, expand all the collapsed code([+] sign) shown in the left hand pane of the Eclipse which defines that your application is idle and doing nothing at this stage. To make it working, you need to an object which will contain the code snippet written above and has to be modified as given below:

package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
  public void onCreate(Bundle savedInstanceState) {
    super. onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    tv.setText("My First Android App");
    setContentView(tv);
  }
}

Save the changes you have done.

Test your apps in Android Emulator

Now your code is ready to be tested in Android emulator and the same can be done in this way:

  • In Eclipse, choose ‘Run -> Run -> Android Application.’
  • You have to wait for a few minutes until Emulator boots up Android. Your app should run automatically once booting is successful and grey title bar with the app name in it can be visualized. Below this, your text will be displayed.Android_Emulator

Press the ‘Home’ button to return to the Android home screen. Click the ‘Applications’ button to see the list of available apps, including ‘Hello, Android’. Select this to launch your app.Android_output

Test your apps in Real Device

Now you’ve run your app in the emulator successfully, you can try it to run on a real device. Before that you need to make one thing sure that USB driver is installed in the Android SDK and AVD manager and you need to declare your app as debuggable and can be done

  1. In Eclipse, expand your application and double-click ‘AndroidManifest.xml’.
  2. Move to the ‘Application’ tab and select ‘True’ from the ‘Debuggable’ dropdown list.
  3. Save the project.

Connect your Android phone to a spare USB port and wait for Windows to detect it and then perform the following tasks:

  1. In the ‘New hardware’ wizard, choose ‘Locate and install drivers’
  2. Opt to browse your PC for the drivers. Browse to the ‘Android SDK’ folder and locate the subfolder for the USB driver.
  3. Windows should find and install it from here.

Now in your android phone,

  1. Choose ‘Menu’ from the home screen.
  2. Select ‘Applications | Development’.
  3. Enable USB debugging.
  4. Now reconnect it to your PC via USB.

Now to run the apps in your android phone

  1. First check that the SDK can see your phone or not.
  2. Browse to the ‘Tools’ directory in your Android SDK folder.
  3. Launch ‘adb.exe’ and you should be able to see your phone listed as ‘Device’.
  4. In Eclipse, choose ‘Run | Run | Android application in Eclipse’.
  5. As you have your phone and the emulator both connected, you need to specify which you want to run it on from the available devices and emulators.
  6. Select your phone from this list to install and run the app.

I hope you have learnt how to develop an android apps and run it in emulator and android phone but it is not sufficient, to develop advanced apps you need know about different APIs and required to go through sample apps(games,utilities) in order to have better understanding about apps.

Leave a Reply

You must be logged in to post a comment.

© 2015 Techzoomer.com. All Rights Reserved. Privacy Policy