Android activity loading completion events

Source: Internet
Author: User

Many people want to process the event when the activity is loaded. For example, if a popwindow or another window is displayed, but the oncreate method processes the time, the program will report an error: the general idea is that the activity has not been fully loaded and cannot handle the pop-up window event. In fact, it is not just a pop-up window, as long as the activity is used. this event cannot be processed before the activity is loaded. The reason is obvious: the display of popwindow or dialog must be attached to a parent activity. Therefore, after the activity is loaded, neither of them can be displayed.

Fortunately, Android provides developers with a method to solve this problem. This method is onwindowfocuschanged ()

 

The description is as follows:

Called when the currentWindowOf
The activity gains or loses focus. This is the best indicator of whether this activity is visible to the user. The default implementation clears the key tracking state, so shocould always be called.

Note that this provides information about global focus state, which is managed independently of activity lifecycles. As such, while focus changes will generally have some relation to Lifecycle changes (an activity that is
Stopped will not generally get window focus), You shoshould not rely on any particle order between the callbacks here and those in the other lifecycle methods suchonResume().

As a general rule, however, a resumed activity will have window focus... unless it has displayed other dialogs or popups that take input focus, in which case the activity itself will not have focus when the other windows
Have it. Likewise, the system may display system-level windows (such as the status bar notification panel or a system alert) which will temporarily take Window input focus without pausing the foreground activity.

Java code

  1. @ Override
  2. Public void onwindowfocuschanged (Boolean hasfocus)
  3. {
  4. If (hasfocus)
  5. {
  6. }
  7. }

 

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.