You are on page 1of 10

UNIT III

ACTIVITIES, FRAGMENTS, AND INTENTS

Q1. Explain Activities


Refer Unit-II
Q2. Explain Activity Life Cycle
Refer Unit-II
Q3. Explain Intents with its types
An Intent is a simple message object that is used to communicate between android components
such as activities, content providers, broadcast receivers and services. Intents are also used to
transfer data between activities.
Intents are used generally for starting a new activity using startActivity().

• Use of Intent
• For Launching an Activity
• To start a New Service
• For Broadcasting Messages
• To Display a list of contacts in ListView
• Types of Intent in Android
Intent is of two types:
• Implicit Intent
• Explicit Intent
• Implicit Intent
• The implicit intent is the intent where instead of defining the exact components, you
define the action that you want to perform for different activities.
• An Implicit intent specifies an action that can invoke any app on the device to be able to
perform an action. Using an Implicit Intent is useful when your app cannot perform the
action but other apps probably can and you’d like the user to pick which app to use.

The Different Methods Used in Intent


• Action_Main
• Action_Pick
• Action_Chooser
• Action_Dial
• Action_Call
• Action_Send
• Action_SendTo
• Action_View

Q4. Explain Linking Activities Using Intents


• An Android application can contain zero or more activities. When your application has
more than one activity, you may need to navigate from one activity to another. In
Android, you navigate between activities through what is known as an intent.
• will add new Activity by right click on package name under src folder then choose New –
> Other –> AndroidActivity, And give it a name (I will name it “Activity2”) and press
finish button.
Q5. Explain Fragments
• Android Fragment is the part of activity, it is also known as sub-activity. There can be
more than one fragment in an activity. Fragments represent multiple screen inside one
activity.
• Android fragment lifecycle is affected by activity lifecycle because fragments are
included in activity.
• Each fragment has its own life cycle methods that is affected by activity life cycle
because fragments are embedded in activity.
• The FragmentManager class is responsible to make interaction between fragment
objects.

You might also like