Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Android activity lifecycle

4 504 vues

Publié le

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.
Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.
An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time. Each activity can then start another activity in order to perform different actions.
Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack .
When a new activity starts, it is pushed onto the back stack and takes user focus.

Publié dans : Formation

Android activity lifecycle

  1. 1. Activity An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. An application usually consists of multiple activities that are loosely bound to each other.
  2. 2. Activity Each time a new activity starts, the previous activity is stopped, but the system preserves the activity in a stack . When a new activity starts, it is pushed onto the back stack and takes user focus.
  3. 3. Go Phish! 4 Android Activity - >
  4. 4. Activity life cycle - >
  5. 5. Method Description Next onCreate() Called when the activity is first created. onStart() onRestart() Called after your activity has been stopped, just prior to it being started again. Always followed by onStart() onStart() onStart() Called when the activity is becoming visible to the user. Followed by onResume() if the activity comes to the foreground, or onStop() if it becomes hidden. onResume()or onStop() onResume() Called when the activity will start interacting with the user. Always followed by onPause(). onPause() onPause() Called when the system is about to start resuming a previous activity. onResume() or onStop() onStop() Called when the activity is no longer visible to the user. Followed by either onRestart() if this activity is coming back to interact with the user, or onDestroy() if this activity is going away. onRestart() or onDestroy() onDestroy() The final call you receive before your activity is Go Phish! 6 destroyed. nothing
  6. 6. Example: When the Activity first time loads the events are called as below: onCreate() onStart() onResume() When you click on Phone button the Activity goes to the background and the below events are called: onPause() onStop() Exit the phone dialer and the below events will be called: onRestart() onStart() onResume() When you click the back button OR try to finish() the activity the events are called as below: onPause() onStop() onDestroy()
  7. 7. Activity Stack • Activities in the system are managed as an activity stack. An activity has essentially four states: If an activity in the foreground of the screen (at the top of the stack), it is active or running. If an activity is completely obscured by another activity, it is stopped. If an activity has lost focus, it is paused. If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process.

×