java - android threads: stopping a thread with heavy computation -


i doing heavy computation in android application. since dont want block ui-thread, computation in seperate workerthread, extends thread. works fine. have trouble stopping thread. normal way stop thread either using interrupt() oder volatile variable tell thread, should end. works in threads kind of loop. doing computation in thread using external libraries , cannot put isinterrupted()-check library. bad way stop thread using stop()-methode, deprecated, in case right way, since thread manipulates internal values. unfortunatly android doesnt support stop(), since doesn't support deprecated thread methods.

10-18 10:26:39.382: error/global(13919): deprecated thread methods not supported. 10-18 10:26:39.382: error/global(13919): java.lang.unsupportedoperationexception 

do other method stop thread in android? in advance! tobias

ps: code show problem:

public void method() {     workerthread t = new workerthread();     t.start();     synchronized (this)     {         try         {             wait(1000);         } catch (interruptedexception e)         {             log.e("",e.tostring(),e);         }         }      //t.stop(); //not supported in android     //t.interrupt(); //can not checked thread     }  class workerthread extends thread {     public void run()     {         externallibrary.heavycomputation();     } } 

generally, unless external library provides protocol stop computation there no way stop gracefully. many written libraries provide such protocol, @ api. may respect interrupt() call. may checked may take time before exits.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -