Android Development Day 2

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Android Development

Day - 2

1
Agenda
Session 1
Introduction to Android Stack
How to Set-Up Development Environment
Setup JDK
Setup Eclipse
Setup Android SDK and Emulator/s

Session 2
Practically set-up the dev-environment
Running a Hello Android Program
Understanding different components of Hello Android
Android Software Development

Java Programming Language


Object Oriented Concepts

3
Android Architecture

4
Application Framework
Developers
can build extremely rich and innovative
applications
have full access to framework APIs

5
Application Framework

Underlying all applications is a set of


services and systems, including:
Views
Content Providers
Resource Manager
Notification Manager
Activity Manager

6
Application Components
no main() function
There are four types of components:
Activities
Services.
Broadcast Receivers
Content providers

7
Types of Android Applications
Foreground Apps
Background
Services and intent receivers
Intermittent
Widget
Developing for Mobile
Hardware imposed design consideration
Low processing power
Limited RAM
Limited storage
Small Screen
High costs of use
Slow data rates
Unreliable Data connection
Limited Battery Life
Mobile Development
Best Practices
Try your best to accommodate the limitations
Be prepared for unreliability
Expect low speeds and high latency
Keep the costs low wherever possible
Make seamless and easy UIs
Android Development Philosophy
Android design philosophy expects apps are designed
for:
Performance
Responsiveness
Seamlessness
Security
Development Kickstart
Step 1 – Downloads:

JDK 5 or 6
http://www.oracle.com/technetwork/java/javase/downl
oads/index.html

Eclipse
http://www.eclipse.org/downloads/

Andriod SDK
http://developer.android.com/sdk/
12
Development Kickstart
Step 2: Install and unzip

Install JDK/Eclipse for Java


Unzip the Eclipse Plugin

13
Development Kickstart
Step 3 – Configure Eclipse and SDK

This includes
Configure Eclipse Plugin for Android
Configure SDK with Eclipse

14
Downloading
Download JDK
Download SDK
Download Eclipse
Configuring Dev Environment
Install JDK
Unzip Eclipse
Add Eclipse Plugin,
How?
Adding Eclipse Plugin
Goto Help Menu
Click Install
Software
Configuring Eclipse
Type following URL
https://dl-ssl.google.com/android/eclipse
Press Add
Wait for the components to load
Select all checkboxes and install the software
Configure Android SDK

19
And you are ready to develop
Lets make a
Hello Android

.........

21
Understanding Hello Example
package com.test9;

import android.app.Activity;
import android.os.Bundle;

public class activity9 extends Activity {


/** Called when the activity is first created. */

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

22
Package and Imports
package com.test9;

import android.app.Activity;
import android.os.Bundle;

23
Activity

public class activity9 extends Activity {

24
onCreate over-ride

public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

25
Where did the Hello string come from?

setContentView(R.layout.main);

This line inflates a Layout Resource already defined


for the user interface layout design.

26
Layout
Layouts can be defined in two ways:

As an XML layout resource

Programmatically in the code

27
Main.xml for Hello Project
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

28
Understanding Layout XML
XML defines which layout you are using
LinearLayout being used right now (we will see other
layouts later)
XML tells you which components to add to the screen,
for examole:
Buttons
Text boxes and text areas
List boxes etc
What does the XML say?

This screen has a Linear Layout


The main view fills the whole screen horizontally and
vertically
This screen has a TextView
Textview fits the height
Why UI in XML?
UI design is done independent of programming
language
Decouples our UI design from your code

Benefits?
Users can work in parallel developing the UI xml and
code.
Resource Types

XML Layouts (res.layout)


String value pairs (res.values)
Drawable icons and images (res.drawable)
String Value Pairs
String value pairs define constants and values that you
need to have initially loaded into the system.

<?xml version="1.0" encoding="utf-8"?>


<resources>
<string name="hello">Hello World, activity!</string>
<string name="app_name">TestApp</string>
</resources>
TextView value

="@string/hello”
Creating the same layout via code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout.LayoutParams lp;
lp = new
LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);

LinearLayout.LayoutParams textViewLP;
textViewLP = new
LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
LinearLayout ll = new LinearLayout(this);

ll.setOrientation(LinearLayout.VERTICAL);

TextView myTextView = new TextView(this);


myTextView.setText("Hello World, HelloWorld");

ll.addView(myTextView, textViewLP);
this.addContentView(ll, lp);
}

You might also like