-3

Any one give idea, Timer will be schedule based on duration array and if once complete duration array length again will be start from first. In this some loop working perfectly some times will be crash and through arrayoutofboundsexception. Any one cane Help Me???

int[] duration={10000,2000,8000};
int layoutIncrment=-1;
private void layoutRotate()
{  layoutIncrment++;
    Timer timer = new Timer();
    timer.schedule(new TimerTask()
    {   public void run()
        {
            if((duration.length-1) <= layoutIncrment)
                layoutIncrment=-1;

            layoutRotate();
            Log.i("Rotation",String.valueOf(layoutIncrment));
    }   },duration[layoutIncrment],100000);
}

1 Answers1

0

why dont u try like this. it will keep running in the while loop.. thats only u want. right?

    int n=1;

    while(n>0)
    {
    for(int i=0;i<duration.length;i++)
    {

    new Handler().postDelayed(new Runnable() {
     @Override
    public void run() {
   //add ur code here
    }
    }, duration[i]);
    }
    }