如何停止Android应用程序的所有工作线程 [英] How to stop all worker threads in android application

查看:208
本文介绍了如何停止Android应用程序的所有工作线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何停止在Android应用程序中所有正在运行的工作线程不回采主线程?

how to stop all running worker threads in an android application without stoping the main thread?

此Any例子吗?

推荐答案

在Java中,不提供方法停止线程。

您只能中断线程,但在该州线程必须可被中断,如睡觉,等...

you can only interrupt thread, but the thread must in the state which can be interrupt, like sleep, wait, etc...

,也可以使用一些技巧,以使线程抛出异常,如:

1.如果线程连接网络,要停止线程,可以关闭网络连接,将抛出IOException异常;

1.if the thread is connect the network, you want to stop thread, you can close the network connection, will throw the ioexception;

2.如果线程读取这个文件,你可以关闭流抛出IOException;

2.if the thread is read the file, you can close the stream to throw ioexception;

3,如果线程查询数据库,就可以关闭数据库

3.if the thread is query the database, you can close the database

所以它取决于你的线程工作。

so it depend on your thread working.

这篇关于如何停止Android应用程序的所有工作线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆