Translate

Friday, 5 February 2016

How to make android apps

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

1.Creating Android Application

The first step is to create a simple Android Application using Eclipse IDE. Follow the option File -> New -> Project and finally select Android New Application wizard from the wizard list. Now name your application as HelloWorld using the wizard window as follows:
Hello Android Wizard
Next, follow the instructions provided and keep all other entries as default till the final step. Once your project is created successfully, you will have following project screen −
Hello Android Project

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.helloworld;  
  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. }  

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