SlideShare une entreprise Scribd logo
1  sur  4
Télécharger pour lire hors ligne
Mobile Computing, Android




                      Activity Life Cycle



                                By :

                  Ahmed Khaled El-Daly / 120071120




Supervisor :

                     Dr.Aiman Ahmed Abu Samra




Date: 27/6/2012
Android App Development: Activity Life Cycle
    The activity is the core of an android application. Each application can have one or more activities.


    In this post we are going to explore the activity’s life cycle and understand the event handler of each
    stage through the activity’s life cycle.


    Activities in the system are managed in an activity stack (Last in Last out). When a new activity is
    launched it becomes on the top of the stack. Any previous activity will be below it and won’t come to the
    top until the new one exists.


    The application on the top of the stack has the highest priority from the operating system. While the
    activity that is not visible has lower priority even if the a running activity requires more memory, the
    system can shut down that activity to free memory.


    Android runs each activity in a separate process each of which hosts a separate virtual machine.
    Android saves metadata (state) of each activity so that when a new activity launches so that it can
    come back to the activity when the user backtracks.


    The activity can be in one of four states:


    Active: the activity started, is running and is in the foreground.
    Paused: the activity is running and visible but another activity (non full sized) is running on the top or a
    notification is displayed. The user can see the activity but can not interact with it. A paused activity is
    fully alive (maintains state and member information) but can be killed by the system in low memory
    situations.
    Stopped: the activity is running but invisible because the user has launched another activity that comes
    to the foreground the activity is alive (maintains state and member information) but can be killed by the
    system in low memory situations.
    Dead: either the activity is not started or it was in pause or stop state and was terminated by the system
    to free some memory or by asking the user to do so.
    The following figure shows the states of the activity and the methods that handle each state


    The sequence is as follows:

   The activity starts, passes through onCreate(), onStart() the activity is still not visible to the
    user, onResume() then it comes to the foreground and becomes fully running.
   If another activity launches or a notification appears the activity passes through the onPause() method.
    Then there would be two scenarios:
    1.if the system decides to kill your activity due to low memory the activity starts the cycle again
from onCreate() method with Bundle savedInstanceState
    parameter that holds data about the previous state of the
    activity.
    2.If the user resumes the activity by closing the new activity or
    the notification the activity cycle continues from
    the onResume() method
   When the user is about to close the activity the activity
    calls onStop() method thenonDestroy() method when the
    system destroys the activity.
    But if another activity runs while the current one is was not
    shut, the activity calles onStop()method and if it is not killed by
    the system it will call onRestart() method then onStart()mehod
    and continues the cycle.
   onCreate(): will be invoked in three cases:
    - the activity runs for the first time and it will be invoked with null Bundle savedInstanceState parameter.
    - the activity has been running then stopped by the user or destroyed by the system then it would be
    invoked with Bundle savedInstanceState that holds the previous state of the activity.
    - the activity is running and you set the device to different resources like Portrait vs landscape, then the
    activity will be recreated.in this method you will create the user interface, bind data to controls and
    register the event handlers for the controls. Then it is followed byonStart() method.
   onStart(): will be invoked when the activity is first launched or brought back to the foreground
    it would be followed by onResume() if the activity continues and comes to foreground, or byonStop() if
    the activity is killed.
   onRestart(): is invoked in case the activity has been stopped and is about to be run again. Always
    followed by onStart() mehod.
   onResume(); invoked when the activity is about to come to the foreground and is on the top of the
    activity stack. It is the place where you can refresh the controls if the activity is using a service that
    displays some feeds or news. Always followed by onPause() method.
   onPause(): is invoked when another activity launches while the current activity is launched or when the
    system decides to kill the activity. In this method you have to cancel everything you did
    in onResume() method like Stopping threads, stopping animations or clearing usage of resources(eg
    the camera).This method is followed by onResume() if the activity returns back to front or
    by onStop() if the activity is to be invisible.
   onStop(): is invoked when a new activity is about to come over the current one or the current one is to
    be destroyed. Always followed by onResume() if the activity comes back oronDestroy() if the activity is
    to be killed.
   onDestroy():is invoked when the activity is shutting down because the activity
    called finish()[terminated the activity] or because the system needs memory so it decided to kill the
    activity.
    Killable methods:
    There are methods that are “killable” meaning that after theses methods return, the process hosting
    them can kill the activity without executing any further code (due to lack of memory)
    These methods are onPause(), onStop() and onDestroy()
here’s the declaration of the life cycle methods:

         @Override
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
         }

         @Override
         protected void onStart() {
         }

         @Override
         protected void onPause() {
            super.onPause();
         }
         @Override
         protected void onResume() {
            super.onResume();
         }
         @Override
         protected void onRestart() {
            super.onRestart();
         }
         @Override
         protected void onStop() {
            super.onStop();
         }
         @Override
         protected void onDestroy() {
            super.onDestroy();
         }


    Summary:
   The entire activity life cycle is between the onCreate() where you construct the UI and aquire resources
    and onDestroy() method where you release all resources.
   The visible life time of the activity is between onStart() and onStop(). Between the activity is visible to
    the user although he may be unable to interact with it. Between the two methods you persist the state of
    the activity so that if another one comes to the foreground then comes back to the original activity you
    find the state persisted.
   The foreground lifetime is between the onResume() and onPause(). During this time the activity is fully
    interactive with the user. The activity can go through the resume and pause states many times (if the
    device sleeps or a new activity launches) .

Contenu connexe

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Android app development

  • 1. Mobile Computing, Android Activity Life Cycle By : Ahmed Khaled El-Daly / 120071120 Supervisor : Dr.Aiman Ahmed Abu Samra Date: 27/6/2012
  • 2. Android App Development: Activity Life Cycle The activity is the core of an android application. Each application can have one or more activities. In this post we are going to explore the activity’s life cycle and understand the event handler of each stage through the activity’s life cycle. Activities in the system are managed in an activity stack (Last in Last out). When a new activity is launched it becomes on the top of the stack. Any previous activity will be below it and won’t come to the top until the new one exists. The application on the top of the stack has the highest priority from the operating system. While the activity that is not visible has lower priority even if the a running activity requires more memory, the system can shut down that activity to free memory. Android runs each activity in a separate process each of which hosts a separate virtual machine. Android saves metadata (state) of each activity so that when a new activity launches so that it can come back to the activity when the user backtracks. The activity can be in one of four states: Active: the activity started, is running and is in the foreground. Paused: the activity is running and visible but another activity (non full sized) is running on the top or a notification is displayed. The user can see the activity but can not interact with it. A paused activity is fully alive (maintains state and member information) but can be killed by the system in low memory situations. Stopped: the activity is running but invisible because the user has launched another activity that comes to the foreground the activity is alive (maintains state and member information) but can be killed by the system in low memory situations. Dead: either the activity is not started or it was in pause or stop state and was terminated by the system to free some memory or by asking the user to do so. The following figure shows the states of the activity and the methods that handle each state The sequence is as follows:  The activity starts, passes through onCreate(), onStart() the activity is still not visible to the user, onResume() then it comes to the foreground and becomes fully running.  If another activity launches or a notification appears the activity passes through the onPause() method. Then there would be two scenarios: 1.if the system decides to kill your activity due to low memory the activity starts the cycle again
  • 3. from onCreate() method with Bundle savedInstanceState parameter that holds data about the previous state of the activity. 2.If the user resumes the activity by closing the new activity or the notification the activity cycle continues from the onResume() method  When the user is about to close the activity the activity calls onStop() method thenonDestroy() method when the system destroys the activity. But if another activity runs while the current one is was not shut, the activity calles onStop()method and if it is not killed by the system it will call onRestart() method then onStart()mehod and continues the cycle.  onCreate(): will be invoked in three cases: - the activity runs for the first time and it will be invoked with null Bundle savedInstanceState parameter. - the activity has been running then stopped by the user or destroyed by the system then it would be invoked with Bundle savedInstanceState that holds the previous state of the activity. - the activity is running and you set the device to different resources like Portrait vs landscape, then the activity will be recreated.in this method you will create the user interface, bind data to controls and register the event handlers for the controls. Then it is followed byonStart() method.  onStart(): will be invoked when the activity is first launched or brought back to the foreground it would be followed by onResume() if the activity continues and comes to foreground, or byonStop() if the activity is killed.  onRestart(): is invoked in case the activity has been stopped and is about to be run again. Always followed by onStart() mehod.  onResume(); invoked when the activity is about to come to the foreground and is on the top of the activity stack. It is the place where you can refresh the controls if the activity is using a service that displays some feeds or news. Always followed by onPause() method.  onPause(): is invoked when another activity launches while the current activity is launched or when the system decides to kill the activity. In this method you have to cancel everything you did in onResume() method like Stopping threads, stopping animations or clearing usage of resources(eg the camera).This method is followed by onResume() if the activity returns back to front or by onStop() if the activity is to be invisible.  onStop(): is invoked when a new activity is about to come over the current one or the current one is to be destroyed. Always followed by onResume() if the activity comes back oronDestroy() if the activity is to be killed.  onDestroy():is invoked when the activity is shutting down because the activity called finish()[terminated the activity] or because the system needs memory so it decided to kill the activity. Killable methods: There are methods that are “killable” meaning that after theses methods return, the process hosting them can kill the activity without executing any further code (due to lack of memory) These methods are onPause(), onStop() and onDestroy()
  • 4. here’s the declaration of the life cycle methods: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override protected void onStart() { } @Override protected void onPause() { super.onPause(); } @Override protected void onResume() { super.onResume(); } @Override protected void onRestart() { super.onRestart(); } @Override protected void onStop() { super.onStop(); } @Override protected void onDestroy() { super.onDestroy(); } Summary:  The entire activity life cycle is between the onCreate() where you construct the UI and aquire resources and onDestroy() method where you release all resources.  The visible life time of the activity is between onStart() and onStop(). Between the activity is visible to the user although he may be unable to interact with it. Between the two methods you persist the state of the activity so that if another one comes to the foreground then comes back to the original activity you find the state persisted.  The foreground lifetime is between the onResume() and onPause(). During this time the activity is fully interactive with the user. The activity can go through the resume and pause states many times (if the device sleeps or a new activity launches) .