从主应用程序图标启动服务
我的应用程序基本上是一个服务,即没有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
找到了解决方案:
Activity
并在onCreate(...)
方法中调用您的服务,然后调用finish()
。要防止
Activity
打开和关闭时闪烁,请将其用作Activity
的主题(在 AndroidManifest.xml 中):android:theme="@android:style/Theme.Translucent.NoTitleBar"
Found the solution to this:
Activity
and in theonCreate(...)
method call your service and then callfinish()
.To prevent the flashing of the
Activity
opening and closing, use this as the theme of yourActivity
(in the AndroidManifest.xml):android:theme="@android:style/Theme.Translucent.NoTitleBar"
只需创建一个允许用户配置您的应用程序的活动即可。此外,肯定还必须有某种 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?
这不是“应用程序列表”。它是通过
通告将出现在启动器中的活动列表。关键词是“活动”。然后创建一个为用户增加价值的活动。
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".Then create an activity that adds value to the user.