SlideShare a Scribd company logo
1 of 21
Download to read offline
Android Activity
Topics
• What is an Activity?
• Declaration of Activities in manifest file
• Activities and application
• Activity life-cycle
• Activity stack
What is an Activity?
What is an Activity?
• An activity presents a visual user interface (screen)
for one focused endeavor the user can undertake.
> For example, an activity might present a list of menu
items users can choose from or it might display
photographs along with their captions.
> A text messaging application might have one activity
that shows a list of contacts to send messages to, a
second activity to write the message to the chosen
contact, and other activities to review old messages
or change settings.
Activity and Visual Content
• Visual content of the window is provided by a
hierarchy of views
• Each view controls a particular rectangular space
within the window.
> Parent views contain and organize the layout of their
children.
> Leaf views (those at the bottom of the hierarchy) draw in
the rectangles they control and respond to user actions
directed at that space.
• Views are where the activity's interaction with the
user takes place.
> For example, a view might display a small image or
button and initiate an action when the user taps that
image or button.
How Visual Content is Presented?
• Each activity is given a default window to draw
> Typically, the window fills the screen, but it might be
smaller than the screen and float on top of other
windows.
• A view hierarchy is placed within an activity's
window by the Activity.setContentView() method.
> The content view is the View object at the root of the
hierarchy.
Activities and Application
Application is Made up with Activities
• An application might consist of just one or more
Activities
> What the activities are, and how many there are
depends, of course, on the application and its design.
• Typically, one of the activities is marked as the first
one that should be presented to the user when the
application is launched.
> Specified in the AndroidManifest.xml
• Moving from one activity to another is
accomplished by having the current activity start
the next one
How an Activity Launch Another?
• An activity is launched in two ways
> startActivity(Intent intent) - Used when launching
activity (calling activity) does not expect a result
> startActivityForResult(Intent intent) - Used when
launching activity expects a result
• The responding activity can look at the initial intent
that caused it to be launched by calling its
getIntent() method
> (We have not learned Intent yet but think of Intent as
a message that gets passed around between
Activities)
Declaration of Activities in the
Manifest fileanifest file
What is Manifest File?
• Every Activity has to be declared in the Manifest
file - otherwise “Activity Not Found” error condition
occurs
<?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
<application . . . >
<activity android:name="com.example.project.FreneticActivity"
android:icon="@drawable/small_pic.png"
android:label="@string/freneticLabel"
. . . >
</activity>
. . .
</application>
</manifest>
Activity Lifecyclectivity Li
An Activity has three states
• Active or running
> When it is in the foreground of the screen (at the top
of the activity stack for the current task).
> This is the activity that is the focus for the user's
actions.
• Paused
> If it has lost focus but is still visible to the user.
> That is, another activity lies on top of it and that
activity either is transparent or doesn't cover the full
screen, so some of the paused activity can show
through.
> A paused activity is completely alive (it maintains all
state and member information and remains attached
to the window manager), but can be killed by the
system in extreme low memory situations.
An Activity has three states
• Stopped
> If it is completely obscured by another activity.
> It still retains all state and member information.
> However, it is no longer visible to the user so its
window is hidden and it will often be killed by the
system when memory is needed elsewhere.
State Transition Callback Methods
• As an activity transitions from state to state, it is
notified of the change by calls to the following
protected methods:
> void onCreate(Bundle savedInstanceState)
> void onStart()
> void onRestart()
> void onResume()
> void onPause()
> void onStop()
> void onDestroy()
• All activities must implement onCreate() to do the
initial setup when the object is first instantiated
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.
• This method is passed a Bundle object containing
the activity's previous state, if that state was
captured
• Always followed by onStart().
Lifecycle Lifetime
• Entire lifetime
> Between the first call to onCreate() through to a
single final call to onDestroy().
• Visible lifetime
> Between a call to onStart() until a corresponding call
to onStop()
• Foreground lifetime
> Between a call to onResume() until a corresponding
call to onPause()
• The square rectangles
represent callback
methods you can
implement to perform
operations when the
Activity moves
between states.
• The colored ovals are
major states the
Activity can be in.
Activity Stackctivity Sta
Activity Stack
• Activities in the system are managed as an activity
stack.
• When a new activity is started, it is placed on the
top of the stack and becomes the running activity
> The previous activity always remains below it in the
stack, and will not come to the foreground again
until the new activity exits.
Thank you

More Related Content

What's hot

Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycleSoham Patel
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaJAX London
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycleSokngim Sa
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & StreamsEyal Vardi
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & viewsma-polimi
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android Ranjith Kumar
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-polimi
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event HandlingNikmesoft Ltd
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming BasicsEueung Mulyana
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android FragmentsSergi Martínez
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in androidPrawesh Shrestha
 

What's hot (20)

Notification android
Notification androidNotification android
Notification android
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo SilvaAndroid | Android Activity Launch Modes and Tasks | Gonçalo Silva
Android | Android Activity Launch Modes and Tasks | Gonçalo Silva
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
Android ui menu
Android ui menuAndroid ui menu
Android ui menu
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Introduction to Android
Introduction to Android Introduction to Android
Introduction to Android
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
Android Programming Basics
Android Programming BasicsAndroid Programming Basics
Android Programming Basics
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Android studio
Android studioAndroid studio
Android studio
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 

Viewers also liked

Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
Krazykoder struts2 plugins
Krazykoder struts2 pluginsKrazykoder struts2 plugins
Krazykoder struts2 pluginsKrazy Koder
 
Android security
Android securityAndroid security
Android securityKrazy Koder
 
Android stepbystep
Android stepbystepAndroid stepbystep
Android stepbystepKrazy Koder
 
Krazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldrivenKrazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldrivenKrazy Koder
 
Android stepbystep
Android stepbystepAndroid stepbystep
Android stepbystepKrazy Koder
 
Android location
Android locationAndroid location
Android locationKrazy Koder
 
Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapterKrazy Koder
 
Android graphics
Android graphicsAndroid graphics
Android graphicsKrazy Koder
 
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentproviderKrazy Koder
 

Viewers also liked (20)

Android search
Android searchAndroid search
Android search
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
2310 b 06
2310 b 062310 b 06
2310 b 06
 
2310 b 02
2310 b 022310 b 02
2310 b 02
 
Krazykoder struts2 plugins
Krazykoder struts2 pluginsKrazykoder struts2 plugins
Krazykoder struts2 plugins
 
2310 b 03
2310 b 032310 b 03
2310 b 03
 
2310 b 04
2310 b 042310 b 04
2310 b 04
 
Android ui misc
Android ui miscAndroid ui misc
Android ui misc
 
Android security
Android securityAndroid security
Android security
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
Android stepbystep
Android stepbystepAndroid stepbystep
Android stepbystep
 
Krazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldrivenKrazykoder struts2 domain_object_modeldriven
Krazykoder struts2 domain_object_modeldriven
 
2310 b 01
2310 b 012310 b 01
2310 b 01
 
Android stepbystep
Android stepbystepAndroid stepbystep
Android stepbystep
 
Android search
Android searchAndroid search
Android search
 
Android location
Android locationAndroid location
Android location
 
Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapter
 
Android graphics
Android graphicsAndroid graphics
Android graphics
 
Android contentprovider
Android contentproviderAndroid contentprovider
Android contentprovider
 
2310 b 01
2310 b 012310 b 01
2310 b 01
 

Similar to Android activity

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
Android activity
Android activityAndroid activity
Android activityMohNage7
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2DHIRAJ PRAVIN
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxShantanuDharekar
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semaswinbiju1652
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android applicationNikunj Dhameliya
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdfssusere71a07
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Dr. Ramkumar Lakshminarayanan
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database faiz324545
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116PrathishGM
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsqperpetrotech
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intentsperpetrotech
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and EventsHenry Osborne
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & IntentsLope Emano
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptbharatt7
 

Similar to Android activity (20)

11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
Android activity
Android activityAndroid activity
Android activity
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
 
Unit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptxUnit 5 Activity and Activity Life Cycle.pptx
Unit 5 Activity and Activity Life Cycle.pptx
 
android_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last semandroid_mod_3.useful for bca students for their last sem
android_mod_3.useful for bca students for their last sem
 
Anatomy of android application
Anatomy of android applicationAnatomy of android application
Anatomy of android application
 
Android Activities.pdf
Android Activities.pdfAndroid Activities.pdf
Android Activities.pdf
 
Android - Activity, Services
Android - Activity, ServicesAndroid - Activity, Services
Android - Activity, Services
 
Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3Android building blocks and application life cycle-chapter3
Android building blocks and application life cycle-chapter3
 
fragments-activity.pptx
fragments-activity.pptxfragments-activity.pptx
fragments-activity.pptx
 
Data Transfer between activities and Database
Data Transfer between activities and Database Data Transfer between activities and Database
Data Transfer between activities and Database
 
Mad textbook 63-116
Mad textbook 63-116Mad textbook 63-116
Mad textbook 63-116
 
Android
AndroidAndroid
Android
 
Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS Mobile application development: part 1: Andriod Vs IOS
Mobile application development: part 1: Andriod Vs IOS
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
 
Activities, Fragments, and Events
Activities, Fragments, and EventsActivities, Fragments, and Events
Activities, Fragments, and Events
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
 
MD-IV-CH-ppt.ppt
MD-IV-CH-ppt.pptMD-IV-CH-ppt.ppt
MD-IV-CH-ppt.ppt
 

More from Krazy Koder (20)

2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xc
2310 b xc2310 b xc
2310 b xc
 
2310 b xb
2310 b xb2310 b xb
2310 b xb
 
2310 b 17
2310 b 172310 b 17
2310 b 17
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
2310 b 13
2310 b 132310 b 13
2310 b 13
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
2310 b 10
2310 b 102310 b 10
2310 b 10
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 

Android activity

  • 2. Topics • What is an Activity? • Declaration of Activities in manifest file • Activities and application • Activity life-cycle • Activity stack
  • 3. What is an Activity?
  • 4. What is an Activity? • An activity presents a visual user interface (screen) for one focused endeavor the user can undertake. > For example, an activity might present a list of menu items users can choose from or it might display photographs along with their captions. > A text messaging application might have one activity that shows a list of contacts to send messages to, a second activity to write the message to the chosen contact, and other activities to review old messages or change settings.
  • 5. Activity and Visual Content • Visual content of the window is provided by a hierarchy of views • Each view controls a particular rectangular space within the window. > Parent views contain and organize the layout of their children. > Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond to user actions directed at that space. • Views are where the activity's interaction with the user takes place. > For example, a view might display a small image or button and initiate an action when the user taps that image or button.
  • 6. How Visual Content is Presented? • Each activity is given a default window to draw > Typically, the window fills the screen, but it might be smaller than the screen and float on top of other windows. • A view hierarchy is placed within an activity's window by the Activity.setContentView() method. > The content view is the View object at the root of the hierarchy.
  • 8. Application is Made up with Activities • An application might consist of just one or more Activities > What the activities are, and how many there are depends, of course, on the application and its design. • Typically, one of the activities is marked as the first one that should be presented to the user when the application is launched. > Specified in the AndroidManifest.xml • Moving from one activity to another is accomplished by having the current activity start the next one
  • 9. How an Activity Launch Another? • An activity is launched in two ways > startActivity(Intent intent) - Used when launching activity (calling activity) does not expect a result > startActivityForResult(Intent intent) - Used when launching activity expects a result • The responding activity can look at the initial intent that caused it to be launched by calling its getIntent() method > (We have not learned Intent yet but think of Intent as a message that gets passed around between Activities)
  • 10. Declaration of Activities in the Manifest fileanifest file
  • 11. What is Manifest File? • Every Activity has to be declared in the Manifest file - otherwise “Activity Not Found” error condition occurs <?xml version="1.0" encoding="utf-8"?> <manifest . . . > <application . . . > <activity android:name="com.example.project.FreneticActivity" android:icon="@drawable/small_pic.png" android:label="@string/freneticLabel" . . . > </activity> . . . </application> </manifest>
  • 13. An Activity has three states • Active or running > When it is in the foreground of the screen (at the top of the activity stack for the current task). > This is the activity that is the focus for the user's actions. • Paused > If it has lost focus but is still visible to the user. > That is, another activity lies on top of it and that activity either is transparent or doesn't cover the full screen, so some of the paused activity can show through. > A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.
  • 14. An Activity has three states • Stopped > If it is completely obscured by another activity. > It still retains all state and member information. > However, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.
  • 15. State Transition Callback Methods • As an activity transitions from state to state, it is notified of the change by calls to the following protected methods: > void onCreate(Bundle savedInstanceState) > void onStart() > void onRestart() > void onResume() > void onPause() > void onStop() > void onDestroy() • All activities must implement onCreate() to do the initial setup when the object is first instantiated
  • 16. 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. • This method is passed a Bundle object containing the activity's previous state, if that state was captured • Always followed by onStart().
  • 17. Lifecycle Lifetime • Entire lifetime > Between the first call to onCreate() through to a single final call to onDestroy(). • Visible lifetime > Between a call to onStart() until a corresponding call to onStop() • Foreground lifetime > Between a call to onResume() until a corresponding call to onPause()
  • 18. • The square rectangles represent callback methods you can implement to perform operations when the Activity moves between states. • The colored ovals are major states the Activity can be in.
  • 20. Activity Stack • Activities in the system are managed as an activity stack. • When a new activity is started, it is placed on the top of the stack and becomes the running activity > The previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.