2. Application Fundamentals
- Android applications are written in the
Java programming language.
- The Android operating system is a
multi-user Linux system in which each
application is a different user.
- Each process has its own virtual
machine (VM), so an application's code
runs in isolation from other applications.
3. Application Components
- There are four different types of application components. Each type serves a
distinct purpose and has a distinct lifecycle that defines how the component is
created and destroyed:
- Activity
- Service
- Content provider
- Broadcast receiver
4. Activity
An activity represents a single screen with a
user interface. For example, an email
application might have one activity that
shows a list of new emails, another activity to
compose an email, and another activity for
reading emails.
5. Activity Lifecycle
A representation of how each new activity in a task adds an item to the back
stack. When the user presses the Back button, the current activity is destroyed
and the previous activity resumes.
6. Activity Lifecycle
onCreate() - Called when the activity is first created. This
is where you should do all of your normal static set up —
create views, bind data to lists, and so on.
onRestart() - Called after the activity has been stopped,
just prior to it being started again.
onStart() - Called just before the activity becomes visible
to the user.
onResume() - Called just before the activity starts
interacting with the user.
7. Activity Lifecycle
onPause() - Called when the system is about to start
resuming another activity. This method is typically used
to commit unsaved changes to persistent data, stop
animations and other things that may be consuming
CPU, and so on. It should do whatever it does very
quickly, because the next activity will not be resumed
until it returns.
onStop() - Called when the activity is no longer visible to
the user.
onDestroy() - Called before the activity is destroyed. This
is the final call that the activity will receive.
8. Fragment
A Fragment represents a behavior or a
portion of user interface in an Activity. You
can combine multiple fragments in a single
activity to build a multi-pane UI and reuse a
fragment in multiple activities.
9. Fragment Lifecycle
onAttach() - Called when the fragment has been
associated with the activity.
onCreate() - The system calls this when creating the
fragment.
onCreateView() - The system calls this when it's time for
the fragment to draw its user interface for the first time.
onActivityCreated() - Called when the activity's
onCreate() method has returned.
onStart(), onResume() - Same as Activity.
10. Fragment Lifecycle
onPause() - The system calls this method as the first
indication that the user is leaving the fragment (though it
does not always mean the fragment is being destroyed).
onStop() - Called when the Fragment is no longer started.
onDestroyView() - Called when the view hierarchy
associated with the fragment is being removed.
onDestroy() - Called when the fragment is no longer in
use.
onDetach() - Called when the fragment is being
disassociated from the activity.
11. Service
A Service is an application component that can perform
long-running operations in the background and does not
provide a user interface.
Started - A service is "started" when an application
component (such as an activity) starts it by calling
startService().
Bound - A service is "bound" when an application
component binds to it by calling bindService().
A service runs in the main thread of its hosting process -
the service does not create its own thread and does not
run in a separate process (unless you specify otherwise).
12. Content Provider
A content provider manages access to a central
repository of data. A provider is part of an Android
application, which often provides its own UI for working
with the data.
Decide if you need a content provider. You need to build
a content provider if you want to provide one or more of
the following features:
- You want to offer complex data or files to other
applications.
- You want to allow users to copy complex data from your
app into other apps.
- You want to provide custom search suggestions using
the search framework.
13. Broadcast receivers
A broadcast receiver is a
component that responds to
system-wide broadcast
announcements. Many
broadcasts originate from the
system—for example, a
broadcast announcing that the
screen has turned off, the
battery is low, or a picture was
captured.
14. Intents and Intent Filters
Three of the core components of an application - activities,
services, and broadcast receivers - are activated through
messages, called intents.
15. User Interface
All user interface elements in an
Android app are built using View
and ViewGroup objects.
A View is an object that draws
something on the screen that the
user can interact with.
A ViewGroup is an object that
holds other View (and
ViewGroup) objects in order to
define the layout of the interface.
16. User Interface
All user interface elements in an
Android app are built using View
and ViewGroup objects.
A View is an object that draws
something on the screen that the
user can interact with.
A ViewGroup is an object that
holds other View (and
ViewGroup) objects in order to
define the layout of the interface.
17. Linear Layout
LinearLayout is a view group that aligns all
children in a single direction, vertically or
horizontally. You can specify the layout direction
with the android:orientation attribute.
18. Linear Layout Example
All children of a LinearLayout are
stacked one after the other, so a
vertical list will only have one
child per row, no matter how wide
they are, and a horizontal list will
only be one row high (the height
of the tallest child, plus padding).
19. Relative Layout
RelativeLayout is a view group that displays child
views in relative positions. The position of each
view can be specified as relative to sibling
elements (such as to the left-of or below another
view) or in positions relative to the parent
RelativeLayout area (such as aligned to the
bottom, left of center).
20. Relative Layout Example
RelativeLayout lets child views
specify their position relative to
the parent view or to each other
(specified by ID). So you can
align two elements by right
border, or make one below
another, centered in the screen,
centered left, and so on. By
default, all child views are drawn
at the top-left of the layout, so you
must define the position of each
view using the various layout
properties available from
RelativeLayout.LayoutParams.
21. List View
ListView is a view group that displays a list of
scrollable items. The list items are automatically
inserted to the list using an Adapter that pulls
content from a source such as an array or
database query and converts each item result
into a view that's placed into the list.
22. Grid View
GridView is a ViewGroup that displays items in a
two-dimensional, scrollable grid. The grid items
are automatically inserted to the layout using a
ListAdapter.
23. Input Controls
Input controls are the interactive components in
your app's user interface. Android provides a
wide variety of controls you can use in your UI,
such as buttons, text fields, seek bars,
checkboxes, zoom buttons, toggle buttons, and
many more.
24. Buttons
Depending on whether you
want a button with text, an
icon, or both, you can
create the button in your
layout in three ways.
25. Text Fields
Input controls are the interactive components in
your app's user interface. Android provides a
wide variety of controls you can use in your UI,
such as buttons, text fields, seek bars,
checkboxes, zoom buttons, toggle buttons, and
many more.
26. Text Fields
You can specify the type of keyboard you want for your EditText
object with the android:inputType attribute.
There are several different input types available for different
situations. Here are some of the more common values for
android:inputType:
"text" - Normal text keyboard.
"textEmailAddress" -Normal text keyboard with the @ character.
"textUri" - Normal text keyboard with the / character.
"number" - Basic number keypad.
"phone" - Phone-style keypad.
27. Checkboxes / Radio Buttons
Checkboxes allow the user to select one or more
options from a set. Typically, you should present
each checkbox option in a vertical list.
Radio buttons allow the user to select one option
from a set. You should use radio buttons for
optional sets that are mutually exclusive if you
think that the user needs to see all available
options side-by-side.