Code execution after activity creation in android

Total Post:27

 1264  View(s)
Rate this:

I want to execute some code immediately after the form is shown.

I want to check the size of a button on the form and use the same size to create a new button at runtime.

I tried onStart() and onResumed(), but they do not work.

  1. Post:51

    Re: Code execution after activity creation in android

    You can add a globallayout listener. Add the listener at onActivityCreated. Check this example:

    button1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
                    public void onGlobalLayout() {
                        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        } else {
                       //here the size is already available. create new button2 here with the size of button1

      Modified On Apr-06-2018 07:05:26 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.