如何弹出设备主页按钮单击上的所有异步任务
我想停止按下设备主页按钮上的所有异步任务,但问题是当进度对话框运行时,在主页按钮上单击仅进度对话框会终止,并且它确实转到 onKeyDown() 方法,我在其中提到了逻辑杀死我的异步任务。因此,即使应用程序关闭并且我的应用程序崩溃后,异步任务也会在后台运行。是否有任何解决方案可以关闭进度对话框以及单击主页按钮上的所有异步任务
I Want to stop all the async tasks on the device home button press, but the problem is when progress dialog is running, on home button click only the progress dialog kills and it does goto the onKeyDown() method where i have mentioned the logic to kill my async tasks. So async task runs in the background even after the application is closed and my app crashed. Is there any solution to close the progress dialog as well as all async tasks on home button click
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法直接拦截对主页按钮的调用。尽管按下主页按钮时 onPause() 将被调用,因此您可以覆盖该方法并将逻辑放在那里。
查看 http://developer.android.com/guide/topics/fundamentals /activities.html#Lifecycle 了解更多信息
You can't intercept calls to the home button directly.Though when the home button is pressed onPause() will be called, so you can override that method and put your logic there.
Check out http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle for more info
在java中,我们无法停止已经启动并正在运行的
Thread
。AsyncTask
也是如此,但您可以尝试调用
asyncTask.cancel()
,其工作方式类似于thread.interrupt()
。它可能会抛出InterruptedException
。如果后面还有更多代码,这些代码也会执行,所以要小心。In java, we can't stop a
Thread
which has been started and is running. So is theAsyncTask
but you can try call
asyncTask.cancel()
which works likethread.interrupt()
. It may throw anInterruptedException
. If there exists more code behind, these code will execute as well, so take care of it.