Lecture 2-1
Lecture 2-1
APPLICATION
DEVELOPMENT
CONTENTS
Activity
Fragments
Service
Content Provider
Broadcast receivers
Intent
ACTIVITIES
• An activity represents the visual representation of an android application and
typically correspond to one UI screen.
• One activity in an applications is specified as the “main” activity, which is presented
to the user when launching the application for the first time.
An activity is composed of two parts:
Activity’s design (XML file)
Activity’s code (Java file)
ACTIVITIES
Activities start each other
Moving from one activity to another is accomplished by having the current activity start
the next one using intents.
FRAGMENTS
• 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.
SERVICES
• A service is a component which runs in the background, without direct interaction
with the user.
• The Android platform provides and runs predefined system services and every
Android application can use them, given the right permissions.
BROADCAST RECEIVERS
• Receive and react to broadcast announcements.
Examples of broadcasts:
Low battery, power connected, shutdown, timezone changes, etc.
Other applications can initiate broadcasts.
• To create a new Broadcast Receiver, extend the BroadcastReceiver class and
override the onReceive event handler.
CONTENT PROVIDERS
• Makes some of the application data available to other applications.
• It’s the only way to transfer data between applications in Android (no shared files,
shared memory, pipes, etc.)
• Extends the class ContentProvider
• Other applications use a ContentResolver object to access the data provided via a
ContentProvider.
INTENT: THE MESSENGER
• Used to invoke a component from another component.
• The intents can communicate messages among any of the three core components of
an application- activities, services, and broadcast receivers.
• Data across components is also passed through intents.
ACTIVITY
LIFE CYCLE