如何在android启动时启动服务? +需要一些其他建议
我正在构建一个收集有关电池信息的应用程序(使用后台服务)。 我希望这个服务从我打开手机的那一刻起就开始运行,我该怎么做?
另一方面,我想仅在用户单击应用程序时激活应用程序的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确的方法:请参阅 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.