[英]Android File upload service stops when phone goes to sleep?
I have made a service to upload a file on server using the asynchronous android task but when my phone goes to sleep, the process stops.When i keep my phone alive the upload code works perfect. 我已经提供了使用异步android任务在服务器上上传文件的服务,但是当我的手机进入睡眠状态时,该过程将停止。当我保持手机处于活动状态时,上传代码可以正常运行。 What will be the possible solution of it.?
可能的解决方案是什么?
Add a wake lock. 添加唤醒锁。
From the Android developer documentation you can do something like: 从Android开发人员文档中,您可以执行以下操作:
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
Wakelock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
wakeLock.acquire();
Make sure to release the wakelock when you are done like so: 完成后请确保释放唤醒锁:
wakelock.release();
More info here: 更多信息在这里:
https://developer.android.com/training/scheduling/wakelock.html https://developer.android.com/training/scheduling/wakelock.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.