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
HELLO WE MEET AGAIN
Android System Architecture
Android is built on top of Linux kernel.
Android is built on top of Linux kernel. Android uses a number of libraries to perform various functionalities.
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.
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.
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.
Introduction to
xml
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
Simple UI
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
A layout/activity is composed of Views and ViewGroups.
View is something that is visible.
Examples: - TextViews, - Buttons, - TimePicker, - DatePicker
VIEWS
<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
<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
<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
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
Each layout has something unique to it.
Each layout has a purpose!
<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
Does not have any android:orientation.
Affects the layouts inside it
Views are arranged according to references.
RelativeLayout
<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.
LinearLayout RelativeLayout vs
<LinearLayout … > <RelativeLayout … >
… </RelativeLayout>
</LinearLayout>
LETS UNITE!
You can use ViewGroup within ViewGroup
LAYOUTCEPTION!
INTENTS
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
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.
Remember this?
Manifest
Name of the Java package for the application.
It describes the components of the application the activities, services, broadcast receivers, and content providers.
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.
<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
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
HAVE YOU EVER WONDERED WHAT HAPPENS WHEN YOU PRESS THE BACK BUTTON/ HOME BUTTON ON ANDROID?
Activity Life Cycle
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.
THAT’S ALL FOLKS! WE’LL SEE YOU TOMORROW