简体   繁体   English

活动生命周期

[英]Activity Life Cycle

I'm trying to understand An Activity full life-cycle. 我正在努力了解一个活动的完整生命周期。

So I have searched on Google and found lots of tutorials regarding activity life-cycle, but in all tutorials I have not found these methods in life-cycle diagram: 所以我在Google上搜索并发现了很多关于活动生命周期的教程,但在所有教程中我都没有在生命周期图中找到这些方法:
1. OnContentChanged() 1. OnContentChanged()
2. OnPostCreate() 2. OnPostCreate()
3. OnPostResume() 3. OnPostResume()
4. OnWindowfocusChanged() 4. OnWindowfocusChanged()
5. OnuserLeaveHint() 5. OnuserLeaveHint()
6. OnUserInteraction() 6. OnUserInteraction()
7. OnDetachedFromWindow() 7. OnDetachedFromWindow()

I would like to known why these method's are not included in activity life-cycle diagram on android docs. 我想知道为什么这些方法不包含在android docs的活动生命周期图中。

One more question: 还有一个问题:
When an activity is created for the fist time then system calls the OnContentChanged() method as the first method and last call by system is the OnDetachedFromWindow() method when an activity is killed, but android docs says entire lifetime of an Activity happens between OnCreate() and OnDestroy() ? 当第一次创建一个活动时,系统调用OnContentChanged()方法作为第一个方法,系统的最后一次调用是一个活动被杀死时的OnDetachedFromWindow()方法,但是android文档说一个活动的整个生命周期发生在OnCreate()之间OnCreate()OnDestroy()

Check out the Documentation for Activity All of these are in there, and many of them contain more detail than what I've listed here. 查看活动文档所有这些都在那里,其中许多包含的内容比我在此处列出的更详细。

  1. This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView). 只要屏幕的内容视图发生更改(由于调用Window.setContentView或Window.addContentView),就会调用此挂钩。
  2. Called when activity start-up is complete (after onStart() and onRestoreInstanceState(Bundle) have been called). 在活动启动完成时调用(在onStart()和onRestoreInstanceState(Bundle)之后调用)。
  3. Called when activity resume is complete (after onResume() has been called). 在活动恢复完成时调用(在调用onResume()之后调用)。
  4. This hook is called whenever the window focus changes. 只要窗口焦点发生变化,就会调用此钩子。
  5. Called as part of the activity lifecycle when an activity is about to go into the background as the result of user choice. 当活动即将作为用户选择的结果进入后台时,被称为活动生命周期的一部分。 For example, when the user presses the Home key, onUserLeaveHint() will be called, but when an incoming phone call causes the in-call Activity to be automatically brought to the foreground, onUserLeaveHint() will not be called on the activity being interrupted. 例如,当用户按下Home键时,将调用onUserLeaveHint(),但是当传入的电话呼叫导致调用中的Activity自动被带到前台时,onUserLeaveHint()将不会被调用的活动被调用。 In cases when it is invoked, this method is called right before the activity's onPause() callback. 在调用它的情况下,在活动的onPause()回调之前调用此方法。 This callback and onUserInteraction() are intended to help activities manage status bar notifications intelligently; 此回调和onUserInteraction()旨在帮助活动智能地管理状态栏通知; specifically, for helping activities determine the proper time to cancel a notfication. 特别是,帮助活动确定取消通知的适当时间。
  6. Called whenever a key, touch, or trackball event is dispatched to the activity. 每当将密钥,触摸或轨迹球事件分派给活动时调用。
  7. Called when the window has been detached from the window manager. 窗口与窗口管理器分离时调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM