从主应用程序图标启动服务

发布于 2024-10-08 04:34:16 字数 119 浏览 0 评论 0原文

我的应用程序基本上是一个服务,即没有 UI(没有任何类子类化 Activity)。我希望将其显示在应用程序列表中,并在从那里启动服务时运行该服务,其优点是用户可以创建快捷方式以将其显示在主屏幕中。

这可能吗?

My application is basically a service, i.e. has no UI (there isn't any class subclassing Activity). I want to have it displayed in the list of applications and to run the service when it's started from there, with the advantage that the user can create a shortcut to display it in the home screen.

Is this possible?

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

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

发布评论

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

评论(3

冰雪梦之恋 2024-10-15 04:34:16

找到了解决方案:

  1. 创建一个 Activity 并在 onCreate(...) 方法中调用您的服务,然后调用 finish()
  2. 要防止 Activity 打开和关闭时闪烁,请将其用作 Activity 的主题(在 AndroidManifest.xml 中):

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

Found the solution to this:

  1. Create an Activity and in the onCreate(...) method call your service and then call finish().
  2. To prevent the flashing of the Activity opening and closing, use this as the theme of your Activity (in the AndroidManifest.xml):

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

陈年往事 2024-10-15 04:34:16

只需创建一个允许用户配置您的应用程序的活动即可。此外,肯定还必须有某种 UI 作为应用程序的一部分。否则它实际上在做什么以及用户如何控制它?

Just make one Activity that allows the user to configure your application. Also there surely must be some sort of UI as part of the app. Otherwise what is it actually doing and how does the user control it?

蓝海 2024-10-15 04:34:16

我希望将其显示在应用程序列表中,并在从那里启动该服务时运行该服务,其优点是用户可以创建快捷方式以将其显示在主屏幕中。

这不是“应用程序列表”。它是通过 通告将出现在启动器中的活动列表。关键词是“活动”。

创建一个启动服务然后自行完成的虚拟 Activity 可以达到目的,但我有点担心 Activity 加载和关闭时的闪烁。

然后创建一个为用户增加价值的活动。

I want to have it displayed in the list of applications and to run the service when it's started from there, with the advantage that the user can create a shortcut to display it in the home screen.

That is not a "list of applications". It is a list of activities that have advertised via <intent-filter> that they are to appear in the launcher. The key word is "activities".

Creating a dummy Activity that starts the service and then finishes itself does the trick, but I'm a little worried about the flashing of the Activity loading and closing.

Then create an activity that adds value to the user.

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