I know there are tons of questions and answers on this topic here but I am not able to resolve the below issue to resume a thread in my app.
heres is my runnable:-
Runnable ViewPagerVisibleScroll= new Runnable() {
@Override
public void run() {
if (i <= mAdapter.getCount() - 1) {
verticalViewPager.setCurrentItem(i, true);
handler.postDelayed(ViewPagerVisibleScroll, 3000);
i++;
while (isPaused) {
synchronized (ViewPagerVisibleScroll) {
// wait for resume() to be called
try {
ViewPagerVisibleScroll.wait();
// isPaused = false;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
};
pause and resume methods:-
public void pause() {
synchronized (ViewPagerVisibleScroll) {
isPaused = true;
}
}
public synchronized void resume() {
synchronized (ViewPagerVisibleScroll) {
isPaused = false;
// notify anybody waiting on "this"
ViewPagerVisibleScroll.notify();
}
}
My problem is that thread will pause()
when I call pause method but it will not resume when I call resume()
. Please help me to get rid of this issue.