Android Activity Introduction to Life Cycle

Android activity of the life cycle

activity class in the package, inheritance system is as follows:

activity alone, for processing user. Almost all of the activity and user must deal with, so the activity creates a window class, developers can setContentView (View) interface to the UI to create a window into the activity, when activity point to full-screen window, you can also use other ways Implementation: As a floating window (the theme set by windowIsFloating), or embedded into other activity (using ActivityGroup). Most of the Activity subclasses need to implement two interfaces:

  • onCreate (Bundle) interface is initialized activity areas. here usually call setContentView (int) set defined in the resource file UI, using findViewById (int) can be defined in the UI window.
  • onPause () interface is user activity to leave the place, here, any changes should be submitted (usually used for ContentProvider save the data.)

In order to be able to use Context.startActivity (), all of the activity classes must be defined in the relevant document AndroidManifest.xml the "activity" item.

Android activity class is an important part of the application life cycle.

Activity Life Cycle

Activity in the system managed by an Activity stack. When a new Activity starts, will be placed to the top of the stack, as the operation of the Activity, the previous Activity retained in the stack, not into the foreground, until the new Activity exit.

There are four essentially different Activity Status:

  1. Front of the screen (Activity top), called active or operational status (active or running)
  2. If a Activity loses focus, but still visible (a new non-full screen or a transparent Activity Activity was placed in the top of the stack), called the suspended state (Paused). Activity is still a state of suspended vitality (to keep all of the state, membership information, and the window manager to stay connected), but extremely low in the system memory when the will be killed.
  3. If a Activity Activity completely covered by another out, called the stop state (Stopped). It remains all the state and members of the information, but it is no longer visible, so it's window is hidden, when the system memory needs to be used in other places when, Stopped the Activity will be killed.
  4. If an Activity is Paused or Stopped states, the system can remove from memory the Activity, Android system uses two methods to delete, or require the Activity end, either directly kill its process. When the Activity again displayed to the user, it must be restarted and reset the front of the state.

Activity The following figure shows the importance of state transitions, rectangular box shows the state transition between the Activity in the callback interface, developers can override to implement the relevant code to achieve, with the color in which the oval that the state of Activity.

Android Activity Introduction to Life Cycle

In the figure above, Activity has three key cycle:

  1. The entire life cycle, from onCreate (Bundle) start to onDestroy () end. Activity in the onCreate () set all of the "global" state, in onDestory () release all resources. For example: an Activity has a thread running in the background, for downloading data from the network, the Activity can onCreate () to create threads in onDestory () to stop threads.
  2. Shows the life cycle, from onStart () start to onStop () end. During this time, you can see the Activity on the screen, although there may not be in front, can not interact with the user. Between these two interfaces, the need to maintain the UI to the user data and resources, for example: you can register a IntentReceiver onStart to monitor data changes result in changes in UI, when the display when no longer needed, you can onStop () in the cancellation of it. onStart (), onStop () can be called multiple times, because the Activity at any time you can switch between visible and hidden.
  3. Front of the life cycle, from onResume () start to onPause () end. During this time, all of the Activity in the Activity of the front, and user interaction. Activity can be resumed regular and paused in the switch between states, for example: When the device is ready to sleep, when the results of a Activity was distributed, when a new distribution of Intent is the time. Therefore, methods in these interfaces should belong to the code is very lightweight.

Activity throughout the life cycle are defined in the following interface methods, all methods can be overridden. Activity needs to implement all onCreate (Bundle) to initialize the settings, most of the need to implement the Activity onPause () to submit the data changed, the current majority of the Activity also need to implement onFreeze () interface, in order to restore the onCreate (Bundle ) which set the state.

public class Activity extends ApplicationContext {

protected void onCreate (Bundle icicle);

protected void onStart ();

protected void onRestart ();

protected void onResume ();

protected void onFreeze (Bundle outIcicle);

protected void onPause ();

protected void onStop ();

protected void onDestroy ();

标签: inheritance, implementation, interface, resource file, ui, life cycle, vitality, java lang object, class developers, foreground, operational status, top of the stack, relevant document, activity areas
分类: Mobile
时间: 2010-10-22


  1. Android: Activity. Process. BoradcastReceiver life cycle

    Android Activity and processes in the life cycle is a very important issue. Android have taken the process lik ...
  2. Introduction

    The information found in the present Android is not much, but rarely for the Activity of the description, so t ...
  3. The fifth series of tutorials Android: Activity Life Cycle

    Wrote By the previous section, "Android Series IV: Android project directory structure" We already k ...
  4. Android Notes ---- activity of the life cycle

    Activity Life Cycle Originally intended to sum up their own, and later found a good summary of this man, so a ...
  5. The fourth series of tutorials Android: Activity Life Cycle

    A: Activity of the life-cycle approach Android offers a lot of Activity of the life cycle methods, such as we ...
  6. Two minutes to complete so that you understand the life cycle Android Activity (Photo)!

    Hello everybody, today in the Activity Detailed look at the life cycle of Android, First look at Android api p ...
  7. Android Activity type application skills sharing

    Android Activity class in the Android operating system, applications are often important. So how can the right ...
  8. Activity of the life cycle of understanding

    Activity is the Android applications we develop the most important class. This article will relate to the foll ...
  9. Activity of the life cycle of rotating the screen changes

    Activity of the life cycle of rotating the screen changes: 1, Activity does not restart Please AndroidManifest ...
  10. Activity of the life cycle

    In Android, the process life cycle most of the time managed by the system; also because a number of specialty ...
  11. Used in the Android Activity, Service, Broadcast, BroadcastReceiver

    Describes the use of the Android Activity, Service, Broadcast, BroadcastReceiver Activities (Activity) - for t ...
  12. android example of the life cycle

    The fourth lesson in the Activity of the android to explain the life cycle. package; import ...
  13. Android BroadcastReceiver Introduction

    Android BroadcastReceiver us to use in the Android Activity, Service, Broadcast, BroadcastReceiver Activities ...
  14. Fourth Lecture - Android Activity of the preliminary

    Fourth Lecture - Android Activity of the initial
  15. Fourth Lecture - Android Activity of the initial

    Fourth Lecture - Android Activity of the initial
  16. Android android activity set in full screen and get the screen width and height

    android activity set in full screen requestWindowFeature (Window.FEATURE_NO_TITLE); Android get screen width a ...
  17. Android Activity lifecycle (lifecycle) of

    Today, write a program verification Activity of the life cycle, the results are as follows: Background knowled ...
  18. [Zhuantie] Android Activity beautiful custom jump effect

    Jump to customize Android Activity beautiful effect Jump when the two Activity, custom mouse gestures: Intent ...
  19. Android Activity之间传递图片(Bitmap)的方法

    这篇文章介绍了Android Activity之间传递图片(Bitmap)的方法,有需要的朋友可以参考一下 在Android开发中:Activity之间传递参数是常见的事:如果我们要在Activity之间传递图片: 1. ...