Reputation: 35
I have an array list
of a model containing ---> key : { link : ... , duration : .... }
.
I need to load my android web view
after through all the links present in my array list and load them for that specific
duration.
UPDATE:
I tried handler and but it still loads the last web page and making Thread.sleep() hangs the app
Upvotes: 1
Views: 230
Reputation: 430
in a loop of array length limnitation, i=0;i<=array.length();i++
, in there run a handler ,where set the duration value in delaytime.Before next handler start , stop the previous handler.
for(i=0;i<=array.length();i++)
{ handler.removeCallbacks(runnable);
new android.os.Handler().postDelayed(new Runnable() {
@Override
public void run() {
//here set your code to load webview link from array list
webview.loadUrl(url[i]);
}
}, duration[i]); //set duration from array.
}
Upvotes: 1
Reputation: 61
You can use timerTask for specific interval to load your list urls
private static Timer timer;
private TimerTask timerTask;
public void startTimer() {
//set a new Timer
try {
timer = new Timer();
//initialize the TimerTask's job
initializeTimerTask();
//schedule the timer, to wake up every 2 second
timer.schedule(timerTask, AppConstants.bgTaskStartDelay, 2000); //
} catch (Exception e) {
e.printStackTrace();
}
}
// it sets the timer to print the counter every x seconds
public void initializeTimerTask() {
timerTask = new TimerTask() {
public void run() {
try {
// you code here to load url from your array
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
Upvotes: 1