如何保持一个服务在后台运行在用户退出应用程序,即使?应用程序、后台、用户

2023-09-09 21:07:31 作者:情定三生

我开发一个应用程序,在那里我开始一个服务,如果一个特定的功能(在我的应用程序)由用户启用。 我想保持用户退出我的应用程序即使在运行此服务。 我怎样才能做到这一点? plz帮助

I am developing an app where I start a service if a particular feature (in my app) is enabled by user. I want to keep running this service even after user quits my app. How can I do this? plz help

推荐答案

右键从developer.android.com

Right from developer.android.com

一个服务是在后台运行的组件来执行   长时间运行的操作或执行工作远程进程。一个   服务不提供用户界面。例如,一个服务   可能播放音乐在背景中,而用户是在一个不同的   应用,或者它可能取网络上的数据不阻塞   与活动的用户交互。另一组件,如一个   活动中,可以启动该服务,并让它运行或绑定到它,从而   与它进行交互。服务是实现服务的一个子类   你可以了解更多关于它的服务开发指南。

A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it. A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.

所以,只要你创建一个服务,并在用户退出你的应用程序将继续运行。就像上面的例子。

So, as long as you create a service, and the user exits your app it will still run. Just like the example above.

这应该给你你需要的所有信息: http://developer.android.com/guide/topics/fundamentals/services.html

This should give you all the information you need: http://developer.android.com/guide/topics/fundamentals/services.html