Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View.postDelayed why is it an instance method?

Tags:

android

In Android platform, a View object has an instance method postDelayed, which according to the documentation:

Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.

My questions:

  1. Why this method has to be an instance method of View?
  2. Would it be different if I call postDelayed in one view instead of another?

Thanks.

like image 404
Andree Avatar asked Apr 12 '26 18:04

Andree


1 Answers

Why this method has to be an instance method of View?

It references an mAttachInfo data member, in its current implementation, and in turn to that data member's mHandler, which is a Handler that actually does the postDelayed() work (if mAttachInfo is not null). You are welcome to read all of this in the source code.

Would it be different if I call postDelayed in one view instead of another?

In theory, two View instances could work with separate Handler instances. However, from the standpoint of the documented behavior, there should be no difference.

like image 196
CommonsWare Avatar answered Apr 15 '26 09:04

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!