Neerav Agarwal
Neerav Agarwal

Reputation: 33

Can an ACTION_MOVE event reach before ACTION_DOWN event in "onInterceptTouchEvent" method of a ViewGroup in an Android application?

I want to initialize an object "obj" for the first event of a gesture.

If ACTION_DOWN always reaches before ACTION_MOVE, I can just initialize the object by checking if current event is ACTION_DOWN.

While, if there is a possibility of ACTION_MOVE reaching before ACTION_DOWN, I'll need to synchronize the initialization of the object on a lock.

Sample code (By using synchronization) is as follows:

public boolean onInterceptTouchEvent(MotionEvent e) {

    if (object == null) {
        synchronized (lock) {
            if (object == null) {
                object = new MyClass();
            }
        }
    }

    return super.onInterceptTouchEvent(e);
}

Upvotes: 0

Views: 26

Answers (1)

shb
shb

Reputation: 6277

ACTION_DOWN is called right after put your finger on the screen. ACTION_MOVE is called when you keep your finger on the screen start moving it. so technically on ACTION_MOVE, ACTION_DOWN is being called before.

Upvotes: 1

Related Questions