Reputation: 351
i am using handler to show a slideshow of images. but i don't know how to pause the handler and then resume it back again. i can set onclicklistener on imageview but how to pause the handler in it:
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
TatSlideShow.this.updateUI();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
public void updateUI() {
refreshHandler.sleep(3000);
if ((count & 1) == 0) {
refreshHandler.sleep(6000);
tatslide.setImageResource(0);
count++;
} else {
if (i < imgid.length) {
tatslide.setImageResource(imgid[i]);
// imageView.setPadding(left, top, right, bottom);
i++;
count++;
}
}
}
Upvotes: 0
Views: 1509
Reputation: 1265
Handler does not have a timer to tweak.
You can cancel posted Runnable's:
handler.removeCallbacks(yourCallback);
And post again, to resume.
Upvotes: 2
Reputation: 157457
there is no pause
. What you could do is to call removeCallbacks
to remove the runnable and add it again, later, when your "pause" status finish.
Edit:
as @pskink pointed correctly out you are using messages. To remove messages you can call removeMessages()
Upvotes: 0