The first line of code: Android Learning Note: Activity life cycle

Source: Internet
Author: User

The first line of code: Android Guo Lin The stack for the activity is a last-in first-out structure. Activity status
    1. Operating State (S1):
      • The activity is in the state of interaction with the user, which is the activity at the top of the stack.
      • The system generally does not consider reclaiming the memory at that place.
    2. Paused state (S2):
      • Activity is no longer at the top of the stack (another activity comes in frontof the activity), but is still visible.
      • The system considers reclaiming memory only when the memory is very low .
    3. Stop State (S3):
      • Activity is not at the top of the stack & is completely invisible (theactivity is no longervisible).
      • The system saves the activity's corresponding state and variable, but the chance of memory being recycled increases, that is, there is no guarantee that the activity will not be recycled. (Process is killed)
    4. Destroy state (S4):
      • Activity is removed from the stack (call finish () or click the back key).
      • Focus on recovering the memory occupied by activity in this state.
Activity lifetimes
    1. OnCreate ()
      • When activity is created, it is called to complete various initialization operations.
    2. OnStart ()
      • The activity is called when it becomes visible (invisible) by invisible (invisible).
    3. Onresume ()
      • When the activity is ready to be called when interacting with the user, the activity must be at the top of the stack (S1).
    4. OnPause ()
      • Other activity is called (no longer on top of the stack), and key data is saved but still visible (visible, S2).
    5. OnStop ()
      • Called when activity becomes invisible (invisible) (S3).
    6. OnDestroy ()
      • Called before activity is destroyed (S4).
    7. Onrestart ()
      • The activity is called (s3→s1, invisible → visible) before it is changed from the stop state to the running state.
      • Because the memory of the activity may have been reclaimed since onstop (), it is necessary to call Onrestart () before calling OnStart () becomes visible.
Add
    • Other than Onrestart (), the remaining lifetime is one by one correspondence
    • OnCreate () vs OnDestroy ()
    • OnStart () vs OnStop ()
    • Onresume vs OnPause ()

First line of code: Android Learning Note: Activity life cycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.