没有主要业务推出Android应用程序和启动应用程序启动服务 [英] Launch Android application without main Activity and start Service on launching application

查看:137
本文介绍了没有主要业务推出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:

  1. 在您的清单,设定活动主题,以 Theme.Translucent.NoTitleBar
  2. 请不要与你的活动布局麻烦,不叫的setContentView()
  3. 在活动的的onCreate(),与启动服务startService()
  4. 退出的活动结束()一旦你开始了服务。
  1. In your Manifest, set the Activity theme to Theme.Translucent.NoTitleBar.
  2. Don't bother with a layout for your Activity, and don't call setContentView().
  3. In your Activity's onCreate(), start your Service with startService().
  4. 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.

这篇关于没有主要业务推出Android应用程序和启动应用程序启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆