In my application I use GPS to obtain coordinates. I have a button that updates the location. When I update the location using GPS then I create a progressbar. If I stop the progress bar I use
mlocManager.removeUpdates(mlocListener);
in onCancelListener
of the progressbar... When I cancel it then开发者_StackOverflow社区 also some background service runs due to
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
In order to stop it I put my code in a thread. How can I stop the thread since many of the functions (like stop,destroy) are deprecated?
Thread is basically stops now in that way:
You have some variable with synchronize access to it. When you need to stop the thread you set this variable to some value, indicating thread should be stopped.
Thread reads the variable while performing it's execution, and if it sees that variable changes, stops simply returns from
run()
method.
UPD: It is implemented with methods interrupt()
and interrupted()
of Thread
class.
精彩评论