training session 2 - day 2
DESCRIPTION
Android System architecture Brief introduction to XML - Layout, View and View Groups Intent and Intent Filter Android Manifest Android Life CycleTRANSCRIPT
![Page 1: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/1.jpg)
HELLO WE MEET AGAIN
![Page 2: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/2.jpg)
Android System Architecture
![Page 3: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/3.jpg)
![Page 4: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/4.jpg)
Android is built on top of Linux kernel.
![Page 5: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/8.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/9.jpg)
Introduction to
xml
![Page 10: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/10.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/11.jpg)
Simple UI
![Page 12: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/14.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/15.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/16.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/18.jpg)
Each layout has something unique to it.
Each layout has a purpose!
![Page 19: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/19.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/21.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/22.jpg)
LinearLayout RelativeLayout vs
![Page 23: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/23.jpg)
<LinearLayout … > <RelativeLayout … >
… </RelativeLayout>
</LinearLayout>
LETS UNITE!
![Page 24: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/24.jpg)
You can use ViewGroup within ViewGroup
LAYOUTCEPTION!
![Page 25: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/25.jpg)
INTENTS
![Page 26: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/26.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/27.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/28.jpg)
Remember this?
![Page 29: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/29.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/30.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/31.jpg)
<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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/32.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/33.jpg)
HAVE YOU EVER WONDERED WHAT HAPPENS WHEN YOU PRESS THE BACK BUTTON/ HOME BUTTON ON ANDROID?
![Page 34: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/34.jpg)
Activity Life Cycle
![Page 35: Training Session 2 - Day 2](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/35.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042613/554a1f91b4c90507558b5a30/html5/thumbnails/36.jpg)
THAT’S ALL FOLKS! WE’LL SEE YOU TOMORROW