Wednesday, 21 September 2016

Creating android application using java eclipse

Setting up Android Development Environment


Installing Android SDK

In order to start developing for Android you need the Software Development Kit. You can download it for WindowsLinux or for Mac OS X.
Once downloaded you have to install it, on Windows just start the executable file.

Installing Java JDK and Eclipse

The Java Development Kit is needed to develop Android applications since Android is based on Java and XML. Writing Android code is being done using an editor, the best supported ,and in my opinion, the best one around is Eclipse. Eclipse is an opensource freeware editor that is capable of supporting a wide range of programming languages.

Installing the ADT Plugin

Once Eclipse is installed we need to connect the Android SDK with Eclipse, this is being done by the ADT Plugin. Installing this plugin is easily done using eclipse.
  1. Start Eclipse. Navigate in the menu to Help > Install new software..
  2. Press ‘ Add..’,  in the new window that pops up you can fill in Name with an arbitrary name. A good suggestion could be “Android Plugin” and in the location you have to paste :
  3. Click ‘Ok’. Make sure the checkbox for Developer Tools is selected and click “Next”.
  4. Click ‘Next’. Accept al the license agreements, click ‘Finish’ and restart Eclipse.
  5. To configure the plugin : choose Window > Preferences
  6. Select ‘Android’ on the left panel and browse for the Android SDK you downloaded in the first step. (On windows : C:\Program Files (x86)\Android\android-sdk)
  7. Click apply and you’re ready and ok !

Adding platforms and components

On windows, start the SDKManager.exe . Located in C:\Program Files (x86)\Android\android-sdk and install all platforms and components.

 

create New AVD

Follow the steps below to create a new AVD,
  • In Eclipse, select Window -> AVD Manager.
  • Click New…

The Create New AVD dialog appears.
  • Type the name of the AVD, for example “first_avd“.
  • Choose a target.
    • The target is the platform (that is, the version of the Android SDK, such as 2.3.3) you want to run on the emulator. It can be either Android API or Google API.
  • [Optional] an SD card size, say 400
  • [Optional] Snapshot. Enable this to make start up of emulator faster.
    • To test this, enable this option. Get the emulator up and running and put it into the state you want. For example, home screen or menu screen. Now close the emulator. Run it again and now the emulator launches quickly with the saved state.
  • [Optional] Skin.
  • [Optional]You can add specific hardware features of the emulated device by clicking the New… button and selecting the feature. Refer this link for more details on hardware options.
  • Click Create AVD.

Launch Android AVD (Emulator)

After creating a new Android AVD, you can launch it using “Android AVD Manager”.
Open “Android AVD Manager” either from Installation directory or Eclipse IDE and follow the steps as shown below.

how to create the simple hello android application.


In this page, you will know how to create the simple hello android application. We are creating the simple example of android using the Eclipse IDE. For creating the simple example:
  1. Create the new android project
  2. Write the message (optional)
  3. Run the android application

Hello Android Example

You need to follow the 3 steps mentioned above for creating the Hello android application.

1) Create the New Android project

For creating the new android project:
1) Select File > New > Project...
2) Select the android project and click next
hello android example 3) Fill the Details in this dialog box and click finish
hello android example Now an android project have been created. You can explore the android project and see the simple program, it looks like this:
hello android example

2) Write the message

For writing the message we are using the TextView class. Change the onCreate method as:
  1. TextView textview=new TextView(this);  
  2. textview.setText("Hello Android!");  
  3. setContentView(textview);  
Let's see the full code of MainActivity.java file.
  1. package com.example.helloandroid;  
  2. import android.os.Bundle;  
  3. import android.app.Activity;  
  4. import android.view.Menu;  
  5. import android.widget.TextView;  
  6. public class MainActivity extends Activity {  
  7.     @Override  
  8.     protected void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.         TextView textview=new TextView(this);  
  11.         textview.setText("Hello Android!");  
  12.         setContentView(textview);  
  13.     }  
  14.     @Override  
  15.     public boolean onCreateOptionsMenu(Menu menu) {  
  16.         // Inflate the menu; this adds items to the action bar if it is present.  
  17.         getMenuInflater().inflate(R.menu.activity_main, menu);  
  18.         return true;  
  19.     }  
  20. }  

To understand the first android application, visit the next page (internal details of hello android example).


3) Run the android application

To run the android application: Right click on your project > Run As.. > Android Application
The android emulator might take 2 or 3 minutes to boot. So please have patience. After booting the emulator, the eclipse plugin installs the application and launches the activity. You will see something like this:
hello android example

No comments:

Post a Comment