/** * 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, {@link #onUserLeaveHint} will be called, but * when an incoming phone call causes the in-call Activity to be automatically brought to the foreground, *{@link #onUserLeaveHint} will not be called on the activity being interrupted. * * 当用户的操作使一个activity准备进入后台时,此方法会像activity的生命周期的一部分被调用。例如,当用户按下Home键, * Activity#onUserLeaveHint()将会被回调。但是当来电导致来电activity自动占据前台,Activity#onUserLeaveHint()将不会被回调。 */
Activity#onUserLeaveHint()
用户手动离开当前activity,会调用该方法,比如用户主动切换任务,短按home进入桌面等。系统自动切换activity不会调用此方法,如来电,灭屏等。
/** * Called whenever a key, touch, or trackball event is dispatched to the * activity. Implement this method if you wish to know that the user has * interacted with the device in some way while your activity is running. * * <p>All calls to your activity's {@link #onUserLeaveHint} callback will * be accompanied by calls to {@link #onUserInteraction}. * * activity无论分发按键事件、触摸事件或者轨迹球事件都会调用Activity#onUserInteraction()。 * 如果你想知道用户用某种方式和你正在运行的activity交互,可以重写Activity#onUserInteraction()。 * 所有调用Activity#onUserLeaveHint()的回调都会首先回调Activity#onUserInteraction()。 */
Activity#onUserInteraction()
activity在分发各种事件的时候会调用该方法,注意:启动另一个activity,Activity#onUserInteraction()会被调用两次,一次是activity捕获到事件,另一次是调用Activity#onUserLeaveHint()之前会调用Activity#onUserInteraction()。