简体   繁体   English

屏幕关闭并按下主页时如何保持Android服务活跃?

[英]How to keep Android service alive when screen off and home pressed?

I want to know how to let my android service is always running when screen off?我想知道如何让我的 android 服务在屏幕关闭时始终运行?

of course , I set WakeLock , but it's seems not working when screen off ....当然,我设置了 WakeLock ,但是当屏幕关闭时它似乎不起作用......

and at the same time , my app is in background(home pressed)同时,我的应用程序在后台(按下主页)

I try to use notificationManager, yes, it's working even screen off,我尝试使用通知管理器,是的,它甚至可以在屏幕关闭时工作,

but if I want to send data(json) to my web server , it's not working,但是如果我想将数据(json)发送到我的网络服务器,它就不起作用,

does any suggestion?有什么建议吗? By the way , android sdk is 30, Thanks.顺便说一句,android sdk 是 30,谢谢。

Whenever an app runs in the background, it consumes some of the device's limited resources, like RAM.每当应用程序在后台运行时,它都会消耗设备的一些有限资源,例如 RAM。 This can result in an impaired user experience, especially if the user is using a resource-intensive app, such as playing a game or watching video.这可能会导致用户体验受损,尤其是当用户使用资源密集型应用程序(例如玩游戏或观看视频)时。 To improve the user experience, Android 8.0 (API level 26) imposes limitations on what apps can do while running in the background.为了改善用户体验,Android 8.0(API 级别 26)对应用在后台运行时可以执行的操作施加了限制。 This document describes the changes to the operating system, and how you can update your app to work well under the new limitations.本文档介绍了对操作系统的更改,以及如何更新您的应用以在新限制下正常运行。https://developer.android.com/about/versions/oreo/backgroundhttps://developer.android.com/about/versions/oreo/background

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM