developing android apps | module 01
TRANSCRIPT
Module One
• What is Android?
• Android Versions
• Setting up the environment
• Dev Environment
• Create your First App
• Directory Structure
• Architecture
• App interface
• App components
• Testing Environment
• Toast
What is Android ?
• Open source Linux based OS for touch based mobile devices
• Developed by Open Handset Alliance led by Google and other companies like Samsung, HTC and Sony
• First commercial version, Android 1.0, was released in September 2008
Android Versions
• Cupcake (1.5) • Donut (1.6) • Eclair (2.0–2.1) • Froyo (2.2–2.2.3) • Gingerbread (2.3–2.3.7) • Honeycomb (3.0–3.2.6) • Ice Cream Sandwich (4.0–4.0.4) • Jelly Bean (4.1–4.3.1) • KitKat (4.4–4.4.4, 4.4W–4.4W.2) • Lollipop (5.0–5.1.1)
TIP : “W” stands for Android Wear.
Steps for setting up
1. JDK 8 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-
downloads-2133151.html
2. Android SDK Tools http://dl.google.com/android/installer_r24.2-windows.exe
3. Eclipse IDE https://www.eclipse.org/downloads/
4. ADT Plugin for Eclipse https://dl.google.com/android/ADT-23.0.6.zip
1. src This contains the .java source files for
your project.
2. gen This contains the .R file, a compiler-
generated file that references all the resources found in your project. You should not modify this file.
3. bin This folder contains the Android package
files .apk built by the ADT during the build process and everything else needed to run an Android application.
4. res/drawable-hdpi Contains drawable objects that are
designed for high-density screens.
5. res/layout Contains files that define your app's user
interface.
6. res/values Contains XML files that contain a
collection of resources, such as strings and colors definitions.
7. AndroidManifest.xml Configuration File
Code Files
1. Java Code | Main_Activity.java http://www.oracle.com/technetwork/java/javase/downloads/jdk8-
downloads-2133151.html
2. Layout Code | activity_main.xml http://dl.google.com/android/installer_r24.2-windows.exe
3. Stored Strings | Strings.xml https://www.eclipse.org/downloads/
4. Configuration File | Manifest.xml https://dl.google.com/android/ADT-23.0.6.zip
App Interface
• Runs in its own virtual machine & process
• Isolated from other apps
• Typically an app cannot access other apps data
• Is composed of basic components
• App components can be activated individually
App Components
Basic Components Description
Activity Represents a single screen with a UI
Service Background processes like playing music in background
Broadcast Receiver Receives messages from system /apps and lets them act upon them
Content Provider Provides an interface let apps share data with each other
Additional Components
Components Description
Views UI elements that are drawn onscreen including buttons, lists forms etc.
Layouts View hierarchies that control screen format and appearance of the views.
Intents Messages wiring components together.
Resources External elements, such as strings, constants and drawables pictures.
Manifest Configuration file for the application.
Two ways
1. Use an Emulator – Android Virtual Device (AVD)
2. Use a Device – Connect device to PC using a USB cable
Setting up an AVD
1. Launch Eclipse
2. Window > AVD Manager
3. Create New
4. Specify required configuration
5. Start your AVD
6. Wait... for it to launch
Using device
In your phone
1. Settings > Developer options > Check USB Debugging
2. Settings > Security > Check Install from unknown sources
3. Install drivers on your PC for your mobile device
4. Connect device to PC via
USB cable
Using device (Cont.)
In Eclipse
1. Right Click on your project folder > Run As > Android Application
2. Choose a running Android device > Click OK
3. Watch the console window for status updates
Show toast on Button Click
Define a Button in the layout file and assign it a unique ID say "button1".
Alternatively you can drop the button control from the Form
Widgets section in the Graphical Layout Layout file | .xml --------------------------------------- <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Here"/>
Show toast on Button Click
Code file | .java --------------------------------------- Import the android.widget.button class Create an object b1 of the Button class Button b1;
From the onCreate method of an Activity, find the Button with
the id as specified in the layout file b1 = (Button) findViewById(R.id.button1);
Show toast on Button Click
Set the onClickListener for this button b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
// TODO Auto-generated method stub
String s1 = "this string is made on the button click";
Toast.makeText(getApplicationContext(), s1, Toast.LENGTH_SHORT).show();
}
});
Official Resources
• App Developer Resources
https://developer.android.com
• Android Developers Blog
http://android-developers.blogspot.in
Assignment 1
Create an Android app that displays:
Textbox1 :
This is my First Android App
Button1 :
On click : textbox1 text changes to “Button1 pressed”
Button2 :
On click : textbox1 text changes to “Button2 pressed”