0

I have an application.It has an on / off button. When you click on "on" it will calculate some big algorithm and it will give the result in 10 seconds. When the algorithm is running (I don't want to wait 10 seconds) I want to stop it by clicking "off" but my app doesn't respond. It even doesn't handle the onclick event for "off" button. What can I do ??? Thanks

4

2 回答 2

2

没有代码我只能猜测,但听起来你在主线程上做了很多工作,考虑使用AsyncTask

于 2013-06-14T14:32:31.317 回答
0

我认为您需要使用多线程。主用户界面线程必须始终准备好响应用户的请求,因此不建议执行任何可能需要 1 秒的任务。在 Android 中执行多线程的一种方法是使用AsyncTask,所以我建议您尝试使用它。随着大算法在后台运行,用户界面可以响应例如中止按钮。然后,您需要对后台任务进行编程以继续查看是否已请求中止。

于 2013-06-14T14:06:32.173 回答