Tuesday, 3 September 2013

How can I pause an Image View update by pressing a button?

How can I pause an Image View update by pressing a button?

I am a coding an app that receives images over a network continuously and
has a handler to post to update the Image View with each new image. I want
to be able to add pause and resume buttons in order to stop the image view
from updating with the new images until the resume button is pressed. Here
is the code that I have for those buttons so far:
Button.OnClickListener pauseOnClickListener = new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
synchronized(imageIn){
try {
imageIn.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
Button.OnClickListener resumeOnClickListener = new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
synchronized(imageIn){
imageIn.notify();
}
}
};
When I run the code and press the pause button, it says that the
application isn't responding. Any comments or suggestions on what I did
wrong will be greatly appreciated.

No comments:

Post a Comment