没有主要业务推出Android应用程序和启动应用程序启动服务
我在application.There一个场景是在我的应用程序没有用户界面,取而代之的是在开始启动时,将连续运行一个服务
I have a scenario in my application.There is no UI in my application;instead there is a Service which starts on boot up and will continuously run.
我该如何配置我的清单文件中没有一个主要的活动?我可以启动我的应用程序没有任何活动?而就发动我的应用程序,我的服务应该启动。以任何方式这可能吗? 我不想让半透明的活动,以启动该服务。
How can I configure my manifest file without a main Activity? Can I launch my app without any Activity? And on launching my app, my Service should start. Is this possible in any way? I don't want to make translucent activities to start the service.
在此先感谢!
你说你不想使用半透明的活动,但是,这似乎是做到这一点的最好办法:
You said you didn't want to use a translucent Activity, but that seems to be the best way to do this:
- 在您的清单,设定活动主题,以
Theme.Translucent.NoTitleBar
。 - 请不要与你的活动布局麻烦,不叫
的setContentView()
。 - 在活动的
的onCreate()
,与启动服务startService()
。 - 退出
的活动结束()
一旦你开始了服务。
- In your Manifest, set the Activity theme to
Theme.Translucent.NoTitleBar
. - Don't bother with a layout for your Activity, and don't call
setContentView()
. - In your Activity's
onCreate()
, start your Service withstartService()
. - Exit the Activity with
finish()
once you've started the Service.
在换句话说,你的活动不必是可见的;它可以简单地确保您的服务正在运行,然后退出,这听起来像你想要的。
In other words, your Activity doesn't have to be visible; it can simply make sure your Service is running and then exit, which sounds like what you want.
我会强烈建议出至少吐司通知指示,你是用户启动服务,或者说,它已在运行。这是非常不好的用户体验有,似乎什么也不做,当你preSS它发射器的图标。
I would highly recommend showing at least a Toast notification indicating to the user that you are launching the Service, or that it is already running. It is very bad user experience to have a launcher icon that appears to do nothing when you press it.