应用程序似乎停止工作时,屏幕进入睡眠状态 [英] App seems to stop working when the screen goes to sleep

查看:137
本文介绍了应用程序似乎停止工作时,屏幕进入睡眠状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CPU密集型的长时间运行的操作(几个小时),我使用的AsyncTask来执行。由于持续下去,更新屏幕上的进度条,显示有多少比例的任务就完成了。

I have a CPU intensive long-running operation (a few hours) that I am using AsyncTask to perform. As it continues, it updates a progressbar on the screen to show what percentage of the task is done.

我发现,当我的屏幕进入睡眠状态(超时)的任务,似乎停止。不知道这是否是happing因为AsyncTask的停止或卡在尝试更新屏幕(后者我想)。

I discovered that when my screen goes to sleep (time-out) the task seems to stop. Not sure whether this is happing because the AsyncTask stops or it gets stuck at trying to update the screen (latter I am thinking).

除了从来没有让屏幕的睡眠,还能怎么我prevent我的AsyncTask停止执行?如果这是唯一的出路,那我怎么确保屏幕不睡觉?

Other than never letting the screen sleep, how else can I prevent my AsyncTask to stop executing? And if that is the only way, then how do I make sure that the screen doesn't sleep?

修改:我要补充一点,我知道这听起​​来像一个非人性化的应用程序的评论被人以下。这确实一个非常特殊的任务(处理成千上万的图像文件进行比较处理在不同的系统上)和是在内部使用的少数用户,而不是公开发布。

EDIT: I must add that I know this sounds like a non-user-friendly app as commented by someone below. This does a very specialized task (processes thousands of image files to compare processing on different systems) and is to be used by a few users internally, not for public release.

推荐答案

这是正常现象。这个想法是,手机的电池是不应该因为糟糕的应用程序的流失。如果屏幕是关闭的,用户普遍预计手机睡觉。

That's expected behavior. The idea is that the phone's battery is not supposed to drain because of bad apps. If the screen is off, the user generally expects the phone to sleep.

如果你需要你的应用程序来运行,你可以使用一个WakeLock继续运行的电话(与屏幕关闭):的文档这里这里

If you need your app to run, you can use a WakeLock to keep the phone running (with the screen off): Documentation here and here.

需要注意的是唤醒锁需要WAKE_LOCK权限,并再次,你需要讲清楚,你的应用程序将喝了手机的奶昔,而它离用户。

Note that a wake lock requires the WAKE_LOCK permission, and again, you need to make it clear to the user that your app will drink the phone's milkshake while it's off.

这篇关于应用程序似乎停止工作时,屏幕进入睡眠状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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