"Android-1" Activity life cycle

Source: Internet
Author: User

I. Four states of activity

Running (Running): indicates activity is active, the user can click on the screen to respond, is also at the top of the activity stack state.

Paused (pause): indicates that the activity loses focus or is occupied by a non-full-screen activity (a transparent activity is at the top of the stack) and may be recycled when memory is tight.

Stopped (stop): When the activity is completely overwritten, the memory tension is still recycled.

killed (killed): indicates that the activity has been reclaimed by the system and that the saved information and member variables are not present.

Ii. Activity life Cycle analysis

1. The activity is first opened to perform the following life cycle methods: OnCreate ()->onstart ()->onresume ()

  onCreate (): The first invocation of the life cycle method, you can do data loading, picture preloading operation.

  OnStart (): indicates that activity is being started, is in a user-visible state, but is not displayed in the foreground and the user cannot interact with the activity, click, swipe (already seen, but cannot touch the state)

  Onresume (): indicates that activity has been visible at the foreground and can interact with the user, touch, swipe, and so on.

2. Click the Home button to return to the main interface (activity is not visible) how to perform: OnPause ()->onstop ()

  onPause (): indicates that activity is in a stopped state (visible, but cannot be touched).

  onStop ():the OnPause () method finishes the call, indicating that activity has stopped and is completely obscured (memory is tight and may be recycled).

3. When returning to the original activity, the following methods are performed: Onrestart ()->onstart ()->onresume ()

  Onrestart (): indicates that a restart is being made visible by an invisible change.

   OnStart (): indicates that activity is being started, is in a user-visible state, but is not displayed in the foreground and the user cannot interact with the activity, click, swipe (already seen, but cannot touch the state) .

   Onresume (): indicates that activity has been visible at the foreground and can interact with the user, touch, swipe, and so on .

4. When exiting the current activity, perform the following life cycle methods: OnPause ()->onstop ()->ondestroy ()

  onPause (): indicates that activity is in a stopped state (visible, but cannot be touched).

  onStop ():the OnPause () method finishes the call, indicating that activity has stopped and is completely obscured (memory is tight and may be recycled).

  OnDestroy (): Activity life cycle The last method, you can do some resource recovery release work

"Android-1" 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.