最近才开始学习android开发,问题比较菜,各位大牛见笑。
通过activity启动service网上教程很多,但是如果一个程序不用activity,直接只启动一个服务,如何才能实现呢?
谢谢各位指点下哈!

解决方案 »

  1.   


    一直工作在后台听着真不像是好需求哇Service自己不能运行,需要通过某一个Activity或者其它Context对象来调用,如Context.startService()和Context.bindService()两种方式启动Service。
      

  2.   

    是安装后APP还没运行就想启动你新注册的服务吗?如果是的话 安装完后会发ACTION_PACKAGE_ADDED广播 但是Sorry the newly installed package does not receive this broadcast.  真要这样的话............. 楼下继续.
      

  3.   

    APP没启动系统怎么会知道有这个BoradcastReceiver呢?
      

  4.   


    可以在androidmanifest内注册广播 
      

  5.   

    你可以在broatcast中 监控 ACTION_TIME_TICK ,来达到启动service。public static final String ACTION_TIME_TICK
    Since: API Level 1Broadcast Action: The current time has changed. Sent every minute. You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver().This is a protected intent that can only be sent by the system.
    Constant Value: "android.intent.action.TIME_TICK"
      

  6.   


    字面上看也不行哦 You can not receive this through components declared in manifests, only by exlicitly registering for it with Context.registerReceiver().
    必须在代码里注册这个广播才能收到,也就是必须先运行APP。