Android--fragment Life Cycle Testing

Source: Internet
Author: User

There are 4 states of activity: running, paused, stopped, and destroyed. There are four different states

Recover the data and status that the system recycles in activity

just opened the interface, activated the first two pages, A-Geneva  +: Wu:27.899 19531-19531/com.ncuhome.usconnection E/tag:zxz:onattach1 A-Geneva  +: Wu:27.899 19531-19531/com.ncuhome.usconnection e/tag:zxz:oncreate2 A-Geneva  +: Wu:27.909 19531-19531/com.ncuhome.usconnection E/tag:zxz:oncreateview3 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection e/tag:zxz:onactivitycreated4 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection E/tag:zxz:onstart5 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection E/tag:zxz:onresume6 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection E/tag:yyxz:onattach1 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection e/tag:yyxz:oncreate2 A-Geneva  +: Wu:27.999 19531-19531/com.ncuhome.usconnection E/tag:yyxz:oncreateview3 A-Geneva  +: Wu:28.009 19531-19531/com.ncuhome.usconnection e/tag:yyxz:onactivitycreated4 A-Geneva  +: Wu:28.009 19531-19531/com.ncuhome.usconnection E/tag:yyxz:onstart5 A-Geneva  +: Wu:28.009 19531-19531/com.ncuhome.usconnection E/tag:yyxz:onresume6 A-Geneva  +: Wu:30.029 19531-19531/com.ncuhome.usconnection E/tag: {"Email":"[email protected]","Phone":{"Home":"08947 000000","Mobile":"9999999999"},"name":"Ravi Tamada"}
When you go to the second interface, the third interface executes to the active state A-Geneva -: to:32.539 26430-26430/com.ncuhome.usconnection E/tag:bgs:onattach1 A-Geneva -: to:32.539 26430-26430/com.ncuhome.usconnection e/tag:bgs:oncreate2 A-Geneva -: to:32.539 26430-26430/com.ncuhome.usconnection E/tag:bgs:oncreateview3 A-Geneva -: to:32.549 26430-26430/com.ncuhome.usconnection e/tag:bgs:onactivitycreated4 A-Geneva -: to:32.549 26430-26430/com.ncuhome.usconnection E/tag:bgs:onstart5 A-Geneva -: to:32.549 26430-26430/com.ncuhome.usconnection E/tag:bgs:onresume6go to the third interface, the first interface executes to 9 A-Geneva -: +:45.939 26430-26430/com.ncuhome.usconnection E/tag:zxz:onpause7 A-Geneva -: +:45.949 26430-26430/com.ncuhome.usconnection E/tag:zxz:onstop8 A-Geneva -: +:45.949 26430-26430/com.ncuhome.usconnection E/tag:zxz:ondestroyview9go to the fourth interface, and the second interface executes to a 9 A-Geneva -: -:28.349 26430-26430/com.ncuhome.usconnection E/tag:yyxz:onpause7 A-Geneva -: -:28.349 26430-26430/com.ncuhome.usconnection E/tag:yyxz:onstop8 A-Geneva -: -:28.349 26430-26430/com.ncuhome.usconnection E/tag:yyxz:ondestroyview9back to the next interface in the office, Office activation starts from Oncreateview. Get dead information in Oncreateview???? First activated, then killed. A-Geneva -:Panax Notoginseng:19.079 26430-26430/com.ncuhome.usconnection E/tag:bgs:oncreateview3 A-Geneva -:Panax Notoginseng:19.089 26430-26430/com.ncuhome.usconnection e/tag:bgs:onactivitycreated4 If the Addtobackstack () method is used. This view is not destroyed A-Geneva -:Panax Notoginseng:19.089 26430-26430/com.ncuhome.usconnection E/tag:bgs:onstart5 A-Geneva -:Panax Notoginseng:19.089 26430-26430/com.ncuhome.usconnection E/tag:bgs:onresume6

In the first interface, click on the third interface, first activate the third interface, in the first interface to perform to 9

conclusion, the open page has been executed until the fragment has been activated,,,, the interface is always displayed to the left and right of the two interface out of the active state, the other interface only executes to 9

1 Operating Status

The fragment is visible and the activity associated with it is in the running state. ---> Fragmentation is in the running state

2 Pause Status

When an activity enters a paused state (another activity that does not occupy the screen is added to the top of the stack), the fragments associated with it go into a paused state.

3. Stop state (fragmentation of the stopped state is completely invisible)

When the activity is in a stopped state, the fragment is stopped, or the remove () replace () method called Fragmenttransaction removes the fragment from the activity, but has a call before the transaction commits Addtobackstack() method. It will go into a stop state and it may be recycled by the system.

Of course, if the Addtobackstack () method is not called at the time of substitution, the rightfragment will go into the destruction state, and the OnDestroy () and Ondetach () methods will be executed.

4 Destruction Status

  

It is also worth mentioning that in the fragment you can also save the data through the onsaveinstancestate () method , because the fragments that go into the stop state may be recycled when the system is low on memory. the saved data can be found in the three methods of OnCreate (), Oncreateview () and onactivitycreated (), and they all contain a Bundle type of The savedinstancestate parameter. Specific code I am not here to give, if you have forgotten how to write can refer to the blog:

  • Onattach () is called when a fragment is associated with an activity
  • OnCreate () Called when creating fragment, where fragment's underlying components must be initialized
  • Oncreateview () fragment to invoke (load layout) when drawing its own interface, this method must return the layout of the fragment, or it can return Null (indicating no interface)
  • onactivitycreated () Called when the activity object completes its own OnCreate method, ensuring that the activity associated with the fragment has been called and completed.
  • OnStart () Fragment UI is visible when called
  • Onresume () Fragment UI can be called interactively when
  • OnPause () Fragment called when visible but not interactive
  • OnStop () Fragment called when it is completely invisible
  • Ondestroyview () Fragment called when the view is removed (called when the layout is removed) when the call is finished, it enters the stop state.
  • OnDestroy () call when cleaning up the view resource
  • Ondetach () Called when fragmentation is associated with an activity

Android--fragment Life Cycle Testing

Related Article

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.