android 工作室中的后台进程|服务

background process|service in android studio

我无法在 google 上找到任何答案,因为不知道如何陈述问题。我想知道如何在 android 中放置一个后台进程或函数,以便及时执行一些操作,例如检查新通知,后台进程应该在任何 activity 中一直工作,即使在应用程序已关闭。

请查看 Foreground Service 上的文档。

注意:您需要显示通知才能启动前台服务。并且不要忘记您的服务在 UI 线程上 运行。

您应该阅读这篇关于 Services . But also, you should read about some limitations that there are especially for Android Oreo and above. For example if you have your app closed the OS may kills your Services. Check this link for Background Execution Limits . If you are looking for notifications you should implement a Service that extends MyFirebaseMessagingService and override onMessageReceived method. Please check this link 的文章。