简体   繁体   English

手机进入睡眠状态时,Android File上传服务会停止吗?

[英]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.

相关问题 Android机会通信与电源管理(电话进入睡眠状态时会发生什么情况) - Android opportunistic communication vs power management (what happens to service when phone goes to sleep) 当应用程序在 android 中进入后台时服务停止 - Service stops when app goes to background in android android当手机进入睡眠状态时如何处理android计时器 - android how to deal with android timer when phone goes to sleep Android 9:手机进入打瞌睡模式后,带有通知的前台服务停止 - Android 9 :Foreground Service with notification stops after phone goes to dozes mode 当电话进入空闲状态时,后台服务停止 - Background service stops when phone goes in idle state 当手机进入睡眠状态时,无法获得android活动 - Cant get android activity to stay on when the phone goes to sleep 手机锁定时,Android服务停止工作 - Android service stops working when phone locked 当手机在android中进入睡眠模式时服务停止 - Service get stopped when mobile goes to sleep mode in android 当电话进入睡眠状态时,活动OnCreate被呼叫 - Activity OnCreate called when phone goes to sleep Android:设备进入睡眠状态并从睡眠状态唤醒时可能启动服务的代码 - Android: possible code to start a service when device goes to sleep and wakes from sleep
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM