I want to kill an specific thread but can't figure out a way of make it work. I include all info next, even if it does not seem important:
I use action bar sherlock and want to kill a thread on an action button event. So, i have:
Thread myThread;
myThread = new Thread(new Runnable(){
public void run(){
functionX();
}
});
myThread.start();
This thread is a long running thread, and funcionX() creates some new threads as well. I want to kill the thread when:
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case android.R.id.home:
myThread.interrupt();
break;
};
I've tried with ExecutorService, using submit(runnable) for a Future result and Future.cancel but does not seems to work. I should also mention that functionX() uses http get requests to get data from a JSON service.
there are multiple ways you can do this,couple of them can be like
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With