android kill specific thread on action bar event

后端 未结 2 753
北海茫月
北海茫月 2020-12-20 21:11

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 sherloc

相关标签:
2条回答
  • 2020-12-20 21:32

    there are multiple ways you can do this,couple of them can be like

    1. Instead of Thread use TimerTask and call timeTask.cancel() - for interrupting
    2. In the run() method of the thread, keep checking a boolean value to determine whether the thread should be terminated and then you can call interrupt or better throw an Exception
    0 讨论(0)
  • 2020-12-20 21:36

    Option 2 from rock_win is the way to go, you can see why here with some code attached:

    http://docs.oracle.com/javase/1.5.0/docs/guide/misc/threadPrimitiveDeprecation.html

    0 讨论(0)
提交回复
热议问题