training session 2 - day 2

36
HELLO WE MEET AGAIN

Upload: vivek-bhusal

Post on 06-May-2015

1.074 views

Category:

Technology


2 download

DESCRIPTION

Android System architecture Brief introduction to XML - Layout, View and View Groups Intent and Intent Filter Android Manifest Android Life Cycle

TRANSCRIPT

Page 1: Training Session 2 - Day 2

HELLO WE MEET AGAIN

Page 2: Training Session 2 - Day 2

Android System Architecture

Page 3: Training Session 2 - Day 2
Page 4: Training Session 2 - Day 2

Android is built on top of Linux kernel.

Page 5: Training Session 2 - Day 2

Android is built on top of Linux kernel. Android uses a number of libraries to perform various functionalities.

Page 6: Training Session 2 - Day 2

Android is built on top of Linux kernel. Android uses a number of libraries to perform various functionalities. Just like the Java Virtual Machine in our computers, Android has its own Dalvik Virtual Machine optimized for itself.

Page 7: Training Session 2 - Day 2

Android is built on top of Linux kernel. Android uses a number of libraries to perform various functionalities. Just like the Java Virtual Machine in our computers, Android has its own Dalvik Virtual Machine optimized for itself. Higher-level services to applications in the form of Java classes: Application Framework.

Page 8: Training Session 2 - Day 2

Android is built on top of Linux kernel. Android uses a number of libraries to perform various functionalities. Just like the Java Virtual Machine in our computers, Android has its own Dalvik Virtual Machine optimized for itself. Higher-level services to applications in the form of Java classes: Application Framework. We will write applications to be installed on the Application layer only.

Page 9: Training Session 2 - Day 2

Introduction to

xml  

Page 10: Training Session 2 - Day 2

Introduction to

xml  

Android’s defined tags

Used to define some of the resources

-  Layouts -  Strings

Preferred way for defining UI elements

-  Separation of code

Used in Android Manifest

Page 11: Training Session 2 - Day 2

Simple UI

Page 12: Training Session 2 - Day 2

Eclipse has a great UI creator -  Generates all the xml for you

Composed of View objects

Can be specified for portrait or landscape

-  Different designs for different orientation.

L OAUYT

Page 13: Training Session 2 - Day 2

A layout/activity is composed of Views and ViewGroups.

View is something that is visible.

Examples: -  TextViews, -  Buttons, -  TimePicker, -  DatePicker

VIEWS

Page 14: Training Session 2 - Day 2

<Button android:id = “@+id/button” android:layout_width = “fill_parent” android:layout_height = “wrap_content” android:text = “Button”/>

3 ways to declare width and height

a.  fill_parent b.  wrap_content c.  match_parent

{

DO NOT FORGET

TO DEFINE US

VIEWS

Page 15: Training Session 2 - Day 2

<EditText android:id = “@+id/number” android:layout_width = “fill_parent” android:layout_height = “wrap_content” android:text = “number”/> {

You can change the type of inputs as necessary

VIEWS

Page 16: Training Session 2 - Day 2

<TextView android:id = “@+id/result” android:layout_height = “wrap_parent” android:layout_weight = “fill_content” android:text = “invisible”/>

VIEWS

3 ways to declare visibility

a.  visible b.  invisible c.  gone

Page 17: Training Session 2 - Day 2

ViewGroups LinearLayout 1

2 RelativeLayout

3 FrameLayout

4 TableLayout

5 ScrollView, etc. This is the <body> to your view. One or more View can be grouped into a ViewGroup

Page 18: Training Session 2 - Day 2

Each layout has something unique to it.

Each layout has a purpose!

Page 19: Training Session 2 - Day 2

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android” android:layout_width= “match_parent” android:layout_height= “match_parent” android:orientation= “vertical”> … (TextViews, Buttons etc.)

</LinearLayout>

LinearLayout

Declaring the XML namespace (done in the 1st ViewGroup)

Unique for this ViewGroup a.  Vertical b.  Horizontal

Page 20: Training Session 2 - Day 2

Does not have any android:orientation.

Affects the layouts inside it

Views are arranged according to references.

RelativeLayout

Page 21: Training Session 2 - Day 2

<RelativeLayout ..> <Button android:id= “@+id/btn” android:layout_alignParentTop= "true" … /> <TextView android:layout_below = “@id/btn” … /> <TextView android:layout_toRightOf = “@id/btn” …/> <TextView android:layout_toLeftOf = “@id/btn” …/> <TextView android:layout_alignParentBottom = “true” .../>

</RelativeLayout>

RelativeLayout

Various other positioning techniques also there: alignLeft alignBaseLine above, etc.

Page 22: Training Session 2 - Day 2

LinearLayout RelativeLayout vs

Page 23: Training Session 2 - Day 2

<LinearLayout … > <RelativeLayout … >

… </RelativeLayout>

</LinearLayout>

LETS UNITE!

Page 24: Training Session 2 - Day 2

You can use ViewGroup within ViewGroup

LAYOUTCEPTION!

Page 25: Training Session 2 - Day 2

INTENTS

Page 26: Training Session 2 - Day 2

INTENTS

<a href= “target”>page 2</a>

Intent ~ Redirecting !

Intent is used to call into android's drivers, other applications as well.

Powerful inter/intra application message-passing framework.

While working with intents we also have to work with the

Android Manifest

Page 27: Training Session 2 - Day 2

Android Manifest

Presents essential information about the application to the Android system Information the system must have before it can run any of the application's code.

Page 28: Training Session 2 - Day 2

Remember this?

Page 29: Training Session 2 - Day 2

Manifest

Name of the Java package for the application.

It describes the components of the application the activities, services, broadcast receivers, and content providers.

Page 30: Training Session 2 - Day 2

Manifest

It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.

It declares the minimum level of the Android API that the application requires … and much more.

Page 31: Training Session 2 - Day 2

<activity android:name=".OtherClass"> <intent-filter> <action android:name="android.intent.action.NAME"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>

MODIFICATION IN ANDROID MANIFEST

Declares an activity (an Activity subclass) that implements part of the application’s visual user interface.

Adds an action to an intent filter

Adds a category name to an intent filter

The types of intents that an app can respond to

Page 32: Training Session 2 - Day 2

In MainActivity Intent i = new Intent(MainActivity.this, OtherClass.class); // Instantiating the intent class i.putExtra(“name”, value); // values to be sent startActivity(i); // Starting the intent

Intents

In OtherClass Intent i = getIntent(); //getting the intent object String name = i.getStringExtra(“name”); //getting value from passed intent

Page 33: Training Session 2 - Day 2

HAVE YOU EVER WONDERED WHAT HAPPENS WHEN YOU PRESS THE BACK BUTTON/ HOME BUTTON ON ANDROID?

Page 34: Training Session 2 - Day 2

Activity Life Cycle

Page 35: Training Session 2 - Day 2

Activity Life Cycle

onCreate() : instantiate views, setup references, implement listeners.

onPause() : save data/state in the application.

onResume() : can be used to load the saved state, is always called when the application comes into view.

Page 36: Training Session 2 - Day 2

THAT’S ALL FOLKS! WE’LL SEE YOU TOMORROW