2

If a code is within Android's postdelayed method, and just below it is more code, does postdelayed lock everything?

Example:

final Handler handler = new Handler ();
            handler.postDelayed (new Runnable () {
                @Override
                public void run () {
                // do something here after 1800millis
                }
            }, 1800);

// something to show on the screen here, this only after 1800millis also?
luke cross
  • 321
  • 1
  • 2
  • 19

1 Answers1

1

Only code that is within the postDelayed will be delayed. It will not block anything that comes after.

Sammy T
  • 1,924
  • 1
  • 13
  • 20
  • You can explain to me the "why"? – luke cross Jan 10 '20 at 11:26
  • I thinked that the after code only executed when the function postDelayed was finished. – luke cross Jan 10 '20 at 11:28
  • 1
    The code within the `Runnable` is what is being delayed. The `Runnable` itself is what is being added to a queue with the set delay duration. Anything that's outside of the Runnable or that isn't triggered by code within the Runnable shouldn't be delayed. You can find out more about postDelayed by visiting [https://developer.android.com/reference/android/os/Handler#postDelayed(java.lang.Runnable,%20long)](https://developer.android.com/reference/android/os/Handler#postDelayed(java.lang.Runnable,%20long)) – Sammy T Jan 10 '20 at 11:34