Unit 2: Android Activities
Topics:
● Creating first android application
● Anatomy of android application
● Deploying Android app on USB connected Android device
● Android application components
● Activity life cycle
● Understanding activities
● Exploring Intent objects
● Intent Types
● Linking activities using intents
2.1 Creating first android application
Creating first android application
● To create the first Android application, go to the next page.
● How to make apps for Hello Android app.Using the Eclipse IDE simple example's
creation:
1. Create the new android project
2. Write the message (optional)
3. Run the android application
Hello Android Example
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
3) Fill the Details in this dialog box and click finish
1
,Android Programming PIET-DS
Now an android project has been created. You can explore the android project and
see the simple program, it looks like this:
2) Write the message
For writing the message we are using the TextView class. Change the onCreate method
as:
TextView textview=new TextView(this);
textview.setText("Hello Android!");
setContentView(textview);
Full code of the MainActivity.java file.
package com.example.helloandroid;
import android.os.Bundle;
import android.app.Activity;
2
, Android Programming PIET-DS
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview=new TextView(this);
textview.setText("Hello Android!");
setContentView(textview);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
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:
Anatomy of android application
First, note the various files that make up an Android project in the Package Explorer in
Eclipse.
3