Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

android - How to forcefully stop thread and start same thread with new variable?

I want to do some long running task on a button click, if user click again on that button current task forcefully stopped and will do next task ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to keep checking a flag in your run method. This flag can be set to false when you want the thread to cancel. The next time your run method checks for this flag, since its false hence it exits the thread. May be you want to use a ThreadPoolExecutor?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...