SlideShare una empresa de Scribd logo
1 de 21
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Android application structure
Android application structureAndroid application structure
Android application structure
Alexey Ustenko
 

La actualidad más candente (20)

Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
04 activities and activity life cycle
04 activities and activity life cycle04 activities and activity life cycle
04 activities and activity life cycle
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
Notification android
Notification androidNotification android
Notification android
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Android application structure
Android application structureAndroid application structure
Android application structure
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Introduction to Android Fragments
Introduction to Android FragmentsIntroduction to Android Fragments
Introduction to Android Fragments
 
Android studio installation
Android studio installationAndroid studio installation
Android studio installation
 
Android Services
Android ServicesAndroid Services
Android Services
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
Android intents
Android intentsAndroid intents
Android intents
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
OOP java
OOP javaOOP java
OOP java
 

Destacado

Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 

Destacado (9)

Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
 
Class 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for BeginnersClass 02 - Android Study Jams: Android Development for Beginners
Class 02 - Android Study Jams: Android Development for Beginners
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
Google Android
Google AndroidGoogle Android
Google Android
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
 
Android studio
Android studioAndroid studio
Android studio
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Slideshare android
Slideshare androidSlideshare android
Slideshare android
 
Activity android
Activity androidActivity android
Activity android
 

Similar a 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.pptx
MugiiiReee
 
Android activity
Android activityAndroid activity
Android activity
MohNage7
 
Android development Training Programme Day 2
Android development Training Programme Day 2Android development Training Programme Day 2
Android development Training Programme Day 2
DHIRAJ 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.pptx
ShantanuDharekar
 
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
aswinbiju1652
 
Android activity intentsq
Android activity intentsqAndroid activity intentsq
Android activity intentsq
perpetrotech
 
Android activity intents
Android activity intentsAndroid activity intents
Android activity intents
perpetrotech
 

Similar a 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
 
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
 
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
 

Más de 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
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

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.