如何在android启动时启动服务? +需要一些其他建议

发布于 2024-11-18 13:07:22 字数 152 浏览 5 评论 0原文

我正在构建一个收集有关电池信息的应用程序(使用后台服务)。 我希望这个服务从我打开手机的那一刻起就开始运行,我该怎么做?

另一方面,我想仅在用户单击应用程序时激活应用程序的 GUI(界面)。应用程序和后台服务位于同一个项目中。

这是做我想做的事的正确方法吗?

I'm building an app that collects info about the battery (using background service).
I want this service to start running from the moment I turn on the phone, How do I do it?

On the other hand I want to activate the GUI (interface) of the app only when the user clicks on the app. The app and the background service are in the same project.

Is this the correct way to do what I want?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渡你暖光 2024-11-25 13:07:22

这是正确的方法:请参阅 https://web.archive.org/web/20210122071943/http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html 有关侦听 BOOT_COMPLETED Intent 的信息。您可以在 BroadcastReceiver 中启动 Service,然后在 Activity 中绑定到它。

That is the correct way to do it: see https://web.archive.org/web/20210122071943/http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html for info about listening for the BOOT_COMPLETED Intent. You can start your Service in the BroadcastReceiver and then bind to it in your Activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文