Code example for Timer

Methods: schedule

0
    	if (mIsAnimation != 0) {
    		return; 
    	} 
    	stopAnimation(); 
    	mIsAnimation = 1;
    	mTimer = new Timer("RainbowTimer");
    	mTimer.schedule(new RainbowTimerTask(), 50, 50);
    	mHandler.post(mInvalidateTask);
    } 
 
    public void stopAnimation() { 
    	if (mIsAnimation == 0) {
    		return; 
    	} 
    	mIsAnimation = 0;
    	if (mTimer != null) {
    		mTimer.cancel();
    		mTimer = null;
    	} 
    	mHandler.post(mInvalidateTask);
    }