Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
hardikhamar
Posts: 159
Registered: 02-17-2011

close thread issue

[ Edited ]

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.

Please use plain text.
Contributor
danz_oye
Posts: 12
Registered: 03-05-2011
My Carrier: XL

Re: close thread issue

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

 

Please use plain text.
Developer
peter_strange
Posts: 14,614
Registered: 07-14-2008

Re: close thread issue

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. 

Please use plain text.