简体   繁体   English

使应用程序在后台运行

[英]Keep app running in background

i made an application which keep the screen awake, and it works fine until it gets killed by the system. 我制作了一个使屏幕保持清醒的应用程序,在它被系统杀死之前,它可以正常工作。 How can i keep my app running in background? 如何使我的应用程序在后台运行? I see a lot of apps that uses notifications to stay running and avoid being killed, but i don't know how to implement it. 我看到很多使用通知来保持运行并避免被杀死的应用程序,但是我不知道如何实现它。 Can someone help me achieve this? 有人可以帮助我实现这一目标吗?

You can use the Service API for this, specifically the startForeground(int, Notification) function call. 您可以为此使用Service API,特别是startForeground(int,Notification)函数调用。 There is an example provided in the API documentation that I have linked to. 我链接到的API文档中提供了一个示例。

服务AlarmManager是您要寻找的,取决于您要执行的操作。

Use Android Services .You can use the following methods:- 使用Android 服务 。您可以使用以下方法:-

  1. To call a Service which doesnt return any value back use - startService() 要调用不返回任何值的服务,请使用-startService()
  2. To call a Service which return back values use - bindService() 要调用返回值的服务,请使用-bindService()

Its good to be cautious when using any Sensors to run in the background as it might eat up you battery fast 使用任何Sensor在后台运行时要格外小心,因为它可能会很快耗尽您的电池电量

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

相关问题 使应用程序在Android上后台运行 - Keep app running in background on Android 让应用始终在 Android 的后台运行 - Keep app running in background on Android all the time 如何保持应用程序在后台运行以及时发送通知? - how to keep app running in background to send timely notifications? 如何让Android应用程序在后台运行 - How can I keep an android app running in background Android如何在用户杀死应用程序后继续运行后台服务? - Android How to keep Running the background service when app is killed by user? Android:保持片段在后台运行 - Android: Keep fragment running in the background 即使应用程序被强制停止,也要重新启动服务,即使关闭应用程序,也要在后台继续运行服务如何? - Restart the service even if app is force-stopped and Keep running service in background even after closing the app How? 即使应用程序被强制停止,也要重新启动服务;关闭应用程序后,仍要在后台运行服务。 - Restart the service even if app is force-stopped and Keep running service in background even after closing the app How? 在后台运行我的应用程序 - Running My App In The Background 如何使用libGDX使我的应用程序在iOS / Android上在后台运行 - How can I keep my app running in the background on iOS/Android with libGDX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM