Which method gets called the moment the activity is fully laid out and ready for user interaction?

android, android-activity

Solution

Commonsware is right, without explaining what your are trying to do and why, it's not possible to answer your question and I suspect, with detail, you are probably thinking about it the wrong way.

However, I do have some code where I needed to do some very funky layout stuff after everything had been measured.

I could have extended each of the view classes in the layout and overriden `onMeasure()` but that would have been a lot of work. So, I ended up doing this. Not great, but it works.

mainMenuLayout is the layout I needed to get funky with. The `onGlobalLayout` callback is called when the layout has completed drawing. `Utils.setTitleText()` is where the funkiness takes place and as I pass mainMenuLayout to it, it has access to the position and size of all of the child views.

mainMenuLayout.getViewTreeObserver().addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {

                    // only want to do this once
                    mainMenuLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);

                    // set the menu title, the empty string check prevents sub-classes
                    // from blanking out the title - which they shouldn't but belt and braces!
                    if (!titleText.equals("")){
                        Utils.setTitleText(_context,mainMenuLayout,titleText);
                    }

                }
            });

Problem

I need a way to run some code at the exact moment in which the activity is fully loaded, laid out, drawn and ready for the user's touch controls. Which method/listener does that?

Original source