Andree
Andree

Reputation: 3103

View.postDelayed why is it an instance method?

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.

Upvotes: 3

Views: 1341

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006944

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.

Upvotes: 2

Related Questions