03-09-2011 01:07 AM - last edited on 03-09-2011 01:09 AM
hello,
i write whole code in thread for image processing which come from webservice.
and i make a Search Page where user enter the value and click on search button.
so according it user get value means images on other page.
now i make Home button in page where images load.
All work properly,but my problem is that when i press Home button it comes on Search Page,but
thread is not close. it works continously until it complete.
So what i write code in home button so it come back and thread will close.so it can again work as per change requirement.
code:
urlclass u=new urlclass(); //my thread object create
home1=new ButtonField("Home page",ButtonField.CONSUME_CLICK);
home1.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field,int content){
if(field==home1)
{
uc.stop();
UiApplication.getUiApplication().pushScreen(new main());
}
}
});
add(home1);
note:in above code main is my search page.
03-09-2011 04:11 AM
we can't kill thread..
a thread will die only if all statement in run() method of that thread excecuted..
maybe you can do this :
public class UrlClass extends Thread {
private boolean isStop = false;
public void run() {
while(!isStop) {
// image processing
}
}
public void stop() {
isStop = true;
}
}just create the class and start it..to stop the thread just invoke stop()
hope this could help
03-09-2011 06:56 PM
Don't know whether it helps much, but I also do a
<thread>.Interrupt()
as part of the close processing.
I also have the Thread in a loop testing a 'stop' condition.