Q:

Simulating touch event in a certain interval in android

What i have done: I am able to simulate touch event using this post 
    // Obtain MotionEvent object
view.setOnTouchListener(new OnTouchListener()
{
    public boolean onTouch(View v, MotionEvent event)
    {
        Toast toast = Toast.makeText(
            getApplicationContext(), 
            "View touched", 
            Toast.LENGTH_LONG
        );
        toast.show();

        return true;
    }
});

// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
    downTime, 
    eventTime, 
    MotionEvent.ACTION_UP, 
    x, 
    y, 
    metaState
);

// Dispatch touch event to view
view.dispatchTouchEvent(motionEvent);

What i am trying to do: 

I want to simulate the touch event every 5 seconds interval.
How to achieve this

A:

   // Obtain MotionEvent object 
view.setOnTouchListener(new OnTouchListener() 
{ 
    public boolean onTouch(View v, MotionEvent event)
    { 
        Toast toast = Toast.makeText(
            getApplicationContext(), 
            "View touched",  
            Toast.LENGTH_LONG
        ); 
        toast.show();

        return true; 
    } 
}); 

// Obtain MotionEvent object 
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState() 
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
    downTime, 
    eventTime, 
    MotionEvent.ACTION_UP, 
    x, 
    y, 
    metaState
); 

// Dispatch touch event to view 
Timer timer = new Timer();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
        runOnUiThread(new Runnable() {
        @Override
        public void run() {
            view.dispatchTouchEvent(motionEvent); 
        }
       });

            }
        },0,5000);

