Mad Unit2

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

UNIT-2

ANDROID UI DESIGN
Topics

GUI for Android:


• Introduction to activities
• activities life-cycle,
• Android v7 support library form API 21 for lower version support
Intent:
• intent object, intent filters
• adding categories
• linking activities
• user interface design components
Views and View Groups:
• Basic views, picker views, adapter views,
• Menu, App Bar etc,
• basics of screen design
• different layouts
• App widgets.
Lollipop Material design:
• new themes
• new widgets
• Card layouts.
• Recycler View
Fragments:
• Introduction to activities, activities life-cycle.
Android Activity Lifecycle
• Android Activity Lifecycle is controlled by 7 methods
of android.app.Activity class. The android Activity is
the subclass of ContextThemeWrapper class.
• An activity is the single screen in android. It is like
window or frame of Java.
• By the help of activity, you can place all your UI
components or widgets in a single screen.
• The 7 lifecycle method of Activity describes how
activity will behave at different states.
Android Activity Lifecycle methods
Android Activity Lifecycle methods
activity_main.xml
• <?xml version="1.0" encoding="utf-8"?>  
• <android.support.constraint.ConstraintLayout xmlns:andr
oid="http://schemas.android.com/apk/res/android"  
•     xmlns:app="http://schemas.android.com/apk/res-
auto"  
•     xmlns:tools="http://schemas.android.com/tools"  
•     android:layout_width="match_parent"  
•     android:layout_height="match_parent"  
•     tools:context="example.javatpoint.com.activitylifecycle.
MainActivity"> 
activity_main.xml
•  <TextView  
•         android:layout_width="wrap_content"  
•         android:layout_height="wrap_content"  
•         android:text="Hello World!"  
•         app:layout_constraintBottom_toBottomOf="parent"  
•         app:layout_constraintLeft_toLeftOf="parent"  
•         app:layout_constraintRight_toRightOf="parent"  
•         app:layout_constraintTop_toTopOf="parent" />    
• </android.support.constraint.ConstraintLayout>  
File: MainActivity.java
• package example.javatpoint.com.activitylifecycle;  
• import android.app.Activity;  
• import android.os.Bundle;  
• import android.util.Log;    
• public class MainActivity extends Activity {  
•     @Override  
•     protected void onCreate(Bundle savedInstanceState) {  
•         super.onCreate(savedInstanceState);  
•         setContentView(R.layout.activity_main);  
•         Log.d("lifecycle","onCreate invoked");  
•     }  
File: MainActivity.java
•     @Override  
•     protected void onStart() {  
•         super.onStart();  
•         Log.d("lifecycle","onStart invoked");  
•     }  
•     @Override  
•     protected void onResume() {  
•         super.onResume();  
•         Log.d("lifecycle","onResume invoked");  
•     }  
File: MainActivity.java
•     @Override  
•     protected void onPause() {  
•         super.onPause();  
•         Log.d("lifecycle","onPause invoked");  
•     }  
•     @Override  
•     protected void onStop() {  
•         super.onStop();  
•         Log.d("lifecycle","onStop invoked");  
•     }  
File: MainActivity.java
•     @Override  
•     protected void onRestart() {  
•         super.onRestart();  
•         Log.d("lifecycle","onRestart invoked");  
•     }  
•     @Override  
•     protected void onDestroy() {  
•         super.onDestroy();  
•         Log.d("lifecycle","onDestroy invoked");  
•     }  
• }  
Uses for the Support Libraries
• There are a few distinct uses for the support
libraries. Here is a more complete list of ways
you can use the support libraries in your app:
– Backward Compatibility for newer APIs - A large
amount of the support libraries provide backward
compatibility for newer framework classes and
methods.
– For example, the Fragment support class provides
support for fragments on devices running versions
earlier than Android 3.0 (API level 11).
Uses for the Support Libraries
– Convenience and Helper Classes - The support libraries
provides a number of helper classes, particularly for user
interface development.
– For example the Recycler View class provides an user
interface widget for displaying and managing very long lists,
useable on versions of Android from API level 7 and up.
– Debugging and Utilities - There are a number of features
that provide utility beyond code you incorporate into your
app, including the support-annotations library for improved
code lint checks on method inputs and Multidex support for
configuring and distributing apps with over 65,536 methods.
Using Support versus Framework APIs
• Support Libraries provide classes and methods
that closely resemble APIs in the Android
Framework. Here are the guidelines for when
you should use support library classes in place of
Framework APIs:
– Compatibility for a Specific Feature - If you want to
support a recent platform feature on devices that a
running earlier versions of the platform, use the
equivalent classes and methods from the support
library.
Using Support versus Framework APIs
– Compatibility for Related Library Features - More
sophisticated support library classes may depend on one
or more additional support library classes, so you should
use support library classes for those dependencies.
– For example, the ViewPager support class should be
used with FragmentPagerAdapter or
the FragmentStatePagerAdapter support classes.
– General Device Compatibility - If you do not have a
specific platform feature you intend to use with your app
in a backward compatible way, it is still a good idea to
use support library classes in your app.
Using Support versus Framework APIs
– For example, you may want to use ActivityCompat in
place of the framework Activity class, so you can take
advantage of newer features later on, such as
incorporating the new permissions model introduced
in Android 6.0 (API level 23).
Android 7.1 Nougat (API 25)
• Rearranged notification shade
• Touch/display performance improvements
• Developer features:
– Shortcut manager APIs.
– Circular app icons support.
– Keyboard image insertion.
– Fingerprint sensor gesture to open/close notification shade.
– Manual storage manager Intent for apps.
– Improved VR thread scheduling.
– Enhanced wallpaper metadata.
– Multi-endpoint call support.
– Battery usage alerts.
API Level: 21
• Android 5.0 (LOLLIPOP) offers new features for users
and app developers. 
• Support for 64-bit CPUs
• Support for print previews
• Vector drawables, which scale without losing definition.
• Material design, bringing a restyled user interface.
• Refreshed lock screen, no longer supporting widgets.
• Refreshed notification tray and quick settings pull-down
• Project Volta, for battery life improvements
API Level: 21
• Updated emoji.
• Smart lock feature.
• Audio input and output through USB devices
• Lock screen provides shortcuts to application
and notification settings.
Intent
• An intent is a type of message
• Whenever you want an activity to start a second activity, you use an
intent.
• It can be used with startActivity to launch
an Activity, broadcastIntent to send it to any
interested BroadcastReceiver components,
and Context.startService(Intent) or Context.bindService(Intent,
ServiceConnection, int) to communicate with a background Service.
• Intent Structure
– Action - The general action to be performed, such
as ACTION_VIEW, ACTION_EDIT, ACTION_MAIN, etc.
– Data - The data to operate on, such as a person record in the contacts
database, expressed as a Uri.
Intent-The first activity passes an intent to Android, Android checks it,
and then Android tells the second activity to start.
Intent creation
• Intent intent = new Intent(this, Target.class);

• Here this refers to current activity and Target.class


specifies next activity to be called
• To start an intent
startActivity(intent) -This tells Android to start the
activity specified by the intent.
• If it can’t find the activity, it throws an
ActivityNotFoundException.
Intents can start activities in other apps

• As an example, we can use an intent to start


the activity in Gmail that sends messages, and
pass it the text we want to send.
• Instead of writing our own activities to send
emails, we can use the existing Gmail app.
Intent Types & actions
• Explicit Intent -- you explicitly tell Android which
class you want it to run. (as discussed above)
• Implicit Intent--If there’s an action you want done
but you don’t mind which activity does it, you
create an implicit intent.
• To create the intent
Intent intent = new Intent(action);
where action is the type of activity action you
want to perform.
Intent Actions
• Some examples of action/data pairs are:
• Intent.ACTION_DIAL to dial a number
• Intent.ACTION_WEB_SEARCH to perform a web search
• Intent.ACTION_SEND to send a message.
Example :
• Intent intent = new Intent(Intent.ACTION_SEND);
• Adding extra information
intent.setType("text/plain");
Intent.putExtra(Intent.EXTRA_TEXT,messageText);
where messageText is the text you want to send.
Methods of Intent

• putExtra() puts extra information in an intent


intent.putExtra("message", value);
ex: intent.putExtra("message", “hello”);
• where message is a String name for the value you’re passing in, and
value is the value.
• The putExtra() method is overloaded so value has many possible types
like string,int float,boolean etc.
• can use putExtra() repeatedly to add numerous extra data to the
intent.
• To retrieve extra information from an intent
getIntent();-- returns the intent that started the activity and you can
use this to retrieve any extra information that was sent along with it.
Intent intent = getIntent();
String string = intent.getStringExtra("message");
int intNum = intent.getIntExtra("name", default_value);
default_value specifies what int value you should use as a default.
Intent code-createMessageActivity class
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
public class CreateMessageActivity extends Activity
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_message);
}
//Call onSendMessage() when the button is clicked
public void onSendMessage(View view) {
Intent intent = new Intent(this, ReceiveMessageActivity.class);
intent.putExtra("message", “hello”);
startActivity(intent);
}
}
Intent code cont…- ReceiveMessageActivity class

package com.hfad.messenger;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
public class ReceiveMessageActivity extends Activity {

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receive_message);
Intent intent = getIntent();
String messageText = intent.getStringExtra(“message”);
TextView messageView = (TextView)findViewById(R.id.message);
messageView.setText(messageText);
}
}
Intent Types
– Explicit Intents have specified a component
(via setComponent(ComponentName) or 
setClass(Context, Class)), which provides the exact class
to be run. Often these will not include any other
information, simply being a way for an application to
launch various internal activities it has as the user
interacts with the application.
– Implicit Intents have not specified a component;
instead, they must include enough information for the
system to determine which of the available components
is best to run for that intent.
Intent – Resolution& Filters
• The intent filter tells Android which activities can
handle which actions
• When Android is given an intent, it has to figure out
which activity, or activities, are able to handle it. This
process is known as intent resolution.
• When you use an explicit intent, intent resolution is
straightforward i.e directly handled by specified target
class.
• When you use an implicit intent, Android uses the
information in the intent to figure out which
components are able to receive it. It does this by
checking the intent filters in every app’s copy of
AndroidManifest.xml.
Inter filter
• Specifies the types of intents that an activity, service,
or broadcast receiver can respond to.
• An intent filter declares the capabilities of its parent
component — what an activity or service can do and
what types of broadcasts a receiver can handle.
• It opens the component to receiving intents of the
advertised type, while filtering out those that are not
meaningful for the component.
• Most of the contents of the filter are described by its
<action>, <category>, and <data> subelements.
Intent filter & Category
• An intent filter specifies what types of intent each component can
receive. As an example, here’s the entry for an activity that can
handle an action of ACTION_SEND. The activity is able to accept
data with MIME types of text/plain or image:
• <activity android:name="ShareActivity">
• <intent-filter>
• <action android:name="android.intent.action.SEND"/>
• <category android:name="android.intent.category.DEFAULT"/>
• <data android:mimeType="text/plain"/>
• <data android:mimeType="image/*"/>
• </intent-filter>
• </activity>
Intent category
• The intent filter also specifies a category. The category
supplies extra information about the activity such as
whether it can be started by a web browser, or if it’s the
main entry point of the app.
• An intent filter must include a category of
android.intent.category.DEFAULT if it’s to receive
implicit intents.
• If an activity has no intent filter, or it doesn’t include a
category name of android.intent.category.DEFAULT, it
means that the activity can’t be started with an implicit
intent.
• It can only be started with an explicit intent using the
fully qualified component name.
Intent attributes
• android:icon
– An icon that represents the parent activity, service, or
broadcast receiver when that component is presented to
the user as having the capability described by the filter.
– This attribute must be set as a reference to a drawable
resource containing the image definition.
– The default value is the icon set by the parent
component's icon attribute.
– If the parent does not specify an icon, the default is the
icon set by the <application> element.
Intent attributes
• android:label
– A user-readable label for the parent component.
– This label, rather than the one set by the parent
component, is used when the component is
presented to the user as having the capability
described by the filter.
– The label should be set as a reference to a string
resource, so that it can be localized like other
strings in the user interface.
Intent attributes
• android:priority
– It provides information about how able an activity is to
respond to an intent that matches the filter, relative to
other activities that could also respond to the intent.
– When an intent could be handled by multiple activities
with different priorities, Android will consider only
those with higher priority values as potential targets for
the intent.

• introduced in: API Level 1


Intent adding category
• A string containing additional information about the kind of
component that should handle the intent.
• Any number of category descriptions can be placed in an intent,
but most intents do not require a category.
• Here are some common categories:
• CATEGORY_BROWSABLE
– The target activity allows itself to be started by a web browser to
display data referenced by a link, such as an image or an e-mail
message.
• CATEGORY_LAUNCHER
– The activity is the initial activity of a task and is listed in the system's
application launcher.
linking activities
• Add a method to the MainActivity class that's
called by the button as follows:
• In the file
– app>java>com.example.myfirstapp>MainActivity,
add the sendMessage() method stub as shown
below:
linking activities
• 1. Create new project with name
“LinkingActivity”
• 2. Open res ➪ layout ➪ activity_main.xml , add
button simple drag drop or  follow this step’s
how to add button in Android Button example ,
after adding new button change its button name 
to “Go To Next “
linking activities
• Now see acitivty_main.xml file code
linking activities
• Now you need second UI for second activity :
Right Click on layout folder ➪ New ➪
Android XML file (pop up box open see figure)
• 4.  Now click add text in
second_activity.xml 
➪ “This is second Activity”
linking activities
• Code of second_activity.xml
linking activities
user interface design components
• Basic Layouts
• Input Controls
• Toast, Dialog and Snackbar
• Navigation, ActionBar and Menus
• Design Support Library
• Image View
• Digital Clock
• Analog Clock
• Text Clock
• SeekBar Example
• Calendar View
• Drop Down List
user interface design components
• A typical user interface of an android
application consists of action bar and the
application content area.
– Main Action Bar
– View Control
– Content Area
– Split Action Bar
Views and View Groups
• View Class are the basic building block for user
interface components. 
• A View occupies a 2-dimensional area (say: rectangle)
on the screen, which is responsible for framing and
handling different type of events.
• Views are used to create input and output fields in the
an Android App.
• It can be input text field, radio field, image field etc.
• They are same as, input text field, image tag to show
images, radio field in HTML.
View Group Class

– The View-Group is the base class


for layouts, which holds other Views and define
their properties.
– Actually an application comprises combination
and nesting of Views-Group and Views Classes.
Basic Views
• Button: Button is pushed or pressed or clicked.
• Every view should have a unique identifier which
identifies the element in the project. Make sure,
two elements should not share their unique ID.
We implement certain methods and interfaces
which listens to user input and act accordingly.
• TextView: This view is basically meant for
displaying the text of application. For example
the label of application is displayed here.
Views cont..
• EditText: This is a modification of Text View. It is editable.
User can give input dynamically.
• Check Box: This widget is a two-state button. It can be
either checked or unchecked.
• Radio Button: This is also a two-state button. It can be
checked or unchecked. Unlike checkbox if it is checked
once, cannot be unchecked. It can be checked dynamically.
• Radio Group: This houses radio buttons together. Checking
any one of the radio buttons in the group unchecks rest of
the buttons. 
Views cont..
• Image Button: This a button with image. User
can press or click this button. Image on the
button is referenced from the src folder of our
project.
Picker View
• Android provides controls for the user to pick
a time or pick a date as ready-to-use dialogs.
• Each picker provides controls for selecting
each part of the time (hour, minute, AM/PM)
or date (month, day, year).
• Using these pickers helps ensure that your
users can pick a time or date that is valid,
formatted correctly, and adjusted to the user's
locale.
Picker View
• We recommend that you use DialogFragment to host each
time or date picker.
• The DialogFragment manages the dialog lifecycle for you
and allows you to display the pickers in different layout
configurations, such as in a basic dialog on handsets or as
an embedded part of the layout on large screens.
• Although DialogFragment was first added to the platform in
Android 3.0 (API level 11), if your app supports versions of
Android older than 3.0—even as low as Android 1.6—you
can use the DialogFragment class that's available in
the supportlibrary for backward compatibility.
Adapter View
Android Adapter is the connector used to connect the data source or database with
our created views.

Adapter Views in Android


Whatever the data set you have, you can directly reflect that dataset using a
specific Adapter View.
data is added, updated, or deleted in the database, the same is reflected in the adapter
view.
The Android Adapter behaved like a bridge allowing the data to flow from the data source
to the Adapter views.
Android Adapter extends the properties from the default Adapter View class for the
specific view.
You can use Adapter View to display a large amount of data efficiently and smoothly on
your user interface.
Adapter Views provides you with many features like adding, deleting and updating the
items in the view.
It also allows you to apply the Context Menu to each of those items.
You can even reload the changes in the Adapter View without even reloading the activity.
Types of Adapter Views

the adapter usually displays the data in three


formats. Those are: List, Grid, and Spinner.
Spinner
 Spinner in Android is
nothing but a dropdown
option.
You can select one item
from the available items in
the spinner.
Difference between a ListView and a Spinner
Types of Android Adapters

There are around six types of Android Adapters that are available to us.
Adapter View constructors
Adapter View -classes & interfaces
Methods involved in Android Adapters
MENU
A Menu is a crucial part of the User Interface that handles frequent functionalities of
the application.
The menu helps us provide a user-friendly interface that handles a lot of actions.
Types of Android Menu
Let us see the various types of menu in
Android:

1. Android Options Menu


The Options Menu is a collection of
options for an activity.
It has a set of items that are useful
to perform actions.
It helps us to combine multiple
actions together.

Following is an example of Options


Menu:
2. PopUp Menu

Pop-Up menu is a menu


that displays a list of items
in a popup window.
 A pop-up menu appears
below the view by default,
in case there is no space, it
appears above it.
3. Contextual Menu

A contextual menu is a
floating menu. It appears
only when the users long-
press an element or right
clicks on that.
 It generally affects the
selected element.
 
App Bar

• The app bar, also known as the action bar, is one of the most


important design elements in your app's activities, because it
provides a visual structure and interactive elements that are familiar
to users.
Using the app bar
• makes your app consistent with other Android apps
• allowing users to quickly understand how to operate your app and
have a great experience.
The key functions of the app bar are as follows:
• A dedicated space for giving your app an identity and indicating the
user's location in the app.
• Access to important actions in a predictable way, such as search.
• Support for navigation and view switching (with tabs or drop-down
lists).
Different Layouts
• Types of layout
– Linear Layout
– Absolute Layout
– Table Layout
– Frame Layout
– Relative Layout
Different Layouts
• Linear Layout
– A linear layout displays views next to each other
either vertically or horizontally. It means it can
arrange views in a single column or in a single row.
Here is the code of linear layout(vertical) that
includes a text view.
Different Layouts
• AbsoluteLayout
– The AbsoluteLayout enables you to specify the
exact location of its children. It can be declared
like this.
Different Layouts
• TableLayout
– The TableLayout groups views into rows and
columns. It can be declared like this.
Relative Layout
• RelativeLayout
– A relative layout displays its views in relative
positions. You define the position of each view
relative to other views in the layout, or relative to
its parent layout. As an example, you can choose
to position a text view relative to the top of the
parent layout, a spinner underneath the text view,
and a button relative to the bottom of the parent
layout.
Width & Height attributes and Padding
• The android:layout_width and android:layout_height attributes specify how wide and high you want
the layout to be.
• These attributes are mandatory for all types of layout and view.
• You can set android:layout_width and android:layout_height to "match_parent", "wrap_content" or a
specific size such as 10dp - 10 density-independent pixels.
• "wrap_content" means that you want the layout to be just big enough to hold all of the views inside
it, and
• "match_parent" means that you want the layout to be as big as its parent—in this case, as big as the
device screen minus any padding.
• In older versions instead of "match_parent“ fill_parent was used
Padding Spaces in any Layout or view:If you want there to be a bit of space around the edge of the
layout, you can set padding attributes.
<RelativeLayout …
android:paddingleft”16dp”
android:paddinright”16dp”
android:paddingtop”16dp”
android:paddingbottom”16dp”

/RelativeLayout>
Relative Layout Attributes for positioning views relative to the
parent layout
Here are some of the most common attributes for positioning views relative to their
parent layout. Add the attribute you want to the view you’re positioning, then set ivalue to
"true":
android:attribute="true"

Attribute What it does


android: layout_alignParentBottom Aligns the bottom edge of the
view to the bottom edge of the parent.
android: layout_alignParentLeft Aligns the left edge of the view
to the left edge of the parent.
android: layout_alignParentRight Aligns the right edge of the view to the right
edge of the parent.
android: layout_alignParentTop Aligns the top edge of the view to the
top edge of the parent.
android: layout_centerInParent Centers the view horizontally and
vertically in the parent.
android: layout_centerHorizontal Centers the view horizontally in the
parent.
android: layout_centerVertical Centers the view vertically in the parent.
Relative Layout Attributes for positioning views relative to
other views and add distance between views
Here are some more of the attributes you can use when positioning views relative to another view.
Add the attribute to the view you’re positioning, and sets its value to the view you’re positioning
relative to:
android:attribute="@+id/view_id"

Attribute What it does


android:layout_above Put the view above the view you’re anchoring
it to.
android:layout_below Puts the view below the view you’re
anchoring it to. android:
android:layout_alignTop Aligns the top edge of the view to the top edge
of the view you’re anchoring it to.
android:layout_alignBottom Aligns the bottom edge of the view to the bottom edge of
the view you’re anchoring it to
android:layout_alignLeft Aligns the left edge of the view to the left edge
of the view you’re anchoring it to.
android:layout_alignRight Aligns the right edge of the view to the right
edge of the view you’re anchoring it to.
Use margins to add distance between views
Ex: android:layout_marginTop="50dp"
Linear Layout Attributes

• A linear layout displays views in the order they appear in


the layout XML
• To specify the Horizontal or vertical arrangements of
views on Linear Layout
android:orientation="vertical"
• Use gravity to specify where text appears in a view.(ex:
content inside a EditText)
android:gravity="value“
ex: android:gravity="top“
The gravity values are –
Top, bottom,left,right,center,center_vertical,
center_horizontal etc..
Different Layouts
• FrameLayout
– The FrameLayout is a placeholder on screen that
you can use to display a single view. It can be
declared like this.
App Widgets
• App widgets can be thought of as a small
window or controller for an Android app that
can be embedded in another application (like
the home screen).
• They can be very useful, allowing users to
view or control an app without actually
launching it. 
New Widgets

Android 5 also introduces new widgets to


simplify and improve the display of collections
of data using

• Recycler View
• Card View
RecyclerView
• The RecyclerView class supports the display of a collection
of data.
• It is a modernized version of the ListView and
the GridView classes provided by the Android framework.
• Recycler view addresses several issues that the existing
widgets have.
• It enforced a programming style that results in good
performance.
• It also comes with default animations for removing and
adding elements.
RecyclerView
• RecyclerView allow to use different layout managers
for positioning items.
• Recycler view uses a ViewHolder to store references
to the views for one entry in the recycler view.
• A ViewHolder class is a static inner class in your
adapter which holds references to the relevant views.
• With these references your code can avoid the time-
consuming findViewById() method to update the
widgets with new data.
Card View
• CardViews can be used to display the row of data in a RecyclerView or ListView. 

• Cards represented by CardViews can be used to display the row of data in a


RecyclerView or ListView. 
Like the rows in a RecyclerView or ListView, a CardView typically serves as the
entry to more detailed information – in a master/detail way. 
  

• In Android 5, CardView extend FrameLayout. 


Per the new Material Design, the CardView provides for the display of the card
information in a panel with rounded corners, raised elevation and make
themselves available to swipe gestures to move them.  
Lollipop Material design
Android 5.0 Lollipop—the largest and most ambitious release for
Android yet!
• This release is packed with new features for users and
thousands of new APIs for developers.
• It extends Android even further, from phones, tablets, and
wearable, to TVs and cars.
• Android 5.0 brings Material design to Android and gives you an
expanded UI toolkit for integrating the new design patterns
easily in your apps.
• New 3D views let you set a z-level to raise elements off of the
view hierarchy and cast realtime shadows, even as they move.
Lollipop Material design
• A new system-managed processing thread
called RenderThread keeps animations smooth even when
there are delays in the main UI thread.
• ART runtime, built from the ground up to support a mix of
ahead-of-time (AOT), just-in-time (JIT), and interpreted code.
• It’s supported on ARM, x86, and MIPS architectures and is
fully 64-bit compatible.
• ART improves app performance and responsiveness. Efficient
garbage collection reduces the number and duration of
pauses for GC events, which fit comfortably within the v-sync
window so your app doesn’t skip frames.
Lollipop Material design
• ART also dynamically moves memory to
optimize performance for foreground uses.
• Notifications
– Notifications in Android 5.0 are more visible,
accessible, and configurable.
– Varying notification details may appear on the lock
screen if desired by the user. Users may elect to
allow none, some, or all notification content to be
shown on a secure lock screen.
Components of Material Design

There are actually several parts to the Material Design.

• A new material theme
• New widgets – particularly for displaying
collections of data
• APIs for creating view elevations and shadows
• APIs for clipping views
• Addition of vector drawables
• APIs for custom animations
Material Theme

• A style in Android is a collection of properties that


specify the look and format for a View.  A theme is a
style applied to an entire Activity or application
• There are new themes
Material Light Theme, Material Dark Theme and
Material Light with Dark Action Bar Theme .
• The Material Design themes allow for activity
transition animations, touch feedback animations and
a color palette that allows for easier branding of the
app.
Fragments
What is Android Fragment?
❑Android Fragment is a Graphical User Interface component of Android. It resides within the 
Activities of an Android application.
❑ It represents a portion of UI that the user sees on the screen. Android Fragments cannot
exist outside an activity.
❑ Another name for Fragment can be Sub-Activity as they are part of Activities.
❑Fragments can be dynamically added and removed as per the requirements. Fragments
improve the adaptability & user experience by making the UI flexible for all devices. All the
Fragments contain their own Events.
❑Fragments generally provide us with a more flexible and wide range of options to make our
Application more interactive. It can make different types of tab displays like scrolling, fixed or
swiping tab. It also makes customizable action bars.
Fragments
• A Fragment represents a behavior or a portion
of user interface in a FragmentActivity.
• You can combine multiple fragments in a
single activity to build a multi-pane UI and
reuse a fragment in multiple activities.
• A fragment must always be hosted in an
activity and the fragment's lifecycle is directly
affected by the host activity's lifecycle.
Types of Android Fragments
1. Single Fragments
Single fragments show only a single view for the user on the screen. These are for handheld
devices such as mobile phones.
2. List Fragments
List fragments are those that have a special list view feature. In this, there’s a list and the
user can choose to see a Sub-Activity.
3. Fragment Transactions
Fragment transactions are for the transition from one fragment to another. It supports
switching between two fragments.
Fragment Life Cycle
• Android fragments have their own life cycle
very similar to an android activity. This section
briefs different stages of its life cycle.
Fragment Life Cycle
• nAttach() The fragment instance is associated with an
activity instance.
• The fragment and the activity is not fully initialized.
Typically you get in this method a reference to the activity
which uses the fragment for further initialization work.
• onCreate() The system calls this method when creating
the fragment.
• You should initialize essential components of the
fragment that you want to retain when the fragment is
paused or stopped, then resumed.
Fragment Life Cycle
• onCreateView() The system calls this callback when it's time
for the fragment to draw its user interface for the first time.
• To draw a UI for your fragment, you must return
a View component from this method that is the root of your
fragment's layout.
• You can return null if the fragment does not provide a UI.
• onActivityCreated() The onActivityCreated() is called after
the onCreateView() method when the host activity is
created.
• Activity and fragment instance have been created as well as
the view hierarchy of the activity.
Fragment Life Cycle
• At this point, view can be accessed with the findViewById()
method.
• onStart() The onStart() method is called once the fragment
gets visible.
• onResume() Fragment becomes active.
• onPause() The system calls this method as the first
indication that the user is leaving the fragment.
• This is usually where you should commit any changes that
should be persisted beyond the current user session.
• onStop() Fragment going to be stopped by calling onStop().
Fragment Life Cycle
• onDestroyView() Fragment view will destroy
after call this method
• onDestroy() onDestroy() called to do final
clean up of the fragment's state but Not
guaranteed to be called by the Android
platform.
Example of Android
Fragments and Activity:

❑The picture shows the


Fragments on the main
activity of Gmail.
❑When we click on one of
the options there like
primary, snoozed, sent, or
some other, another
Fragment opens. For
example,
❑when we click on
Scheduled the following
Activity comes up:

You might also like