楼主是这个意思?public int onStartCommand(Intent intent, int flags, int startId) {
     if(true){ //加个这个,能编过
     while (1>0) {
         try {
         Thread.sleep(4000);
         Log.i("log", "onstart");
         } catch (InterruptedException e) {
         e.printStackTrace();
         }
         }
     }
     return super.onStartCommand(intent, flags, startId);
    }

解决方案 »

  1.   

    主线程回调必须5秒内返回,另建一个线程处理这种东西。另外Android上sleep貌似靠不住,长时间运行恐怕得用Alarm
      

  2.   

    service也不能做超时的操作你这个可以用定时器干。timer和timertask
      

  3.   

    美女,把你邮箱给我,我把项目demo发给你。
      

  4.   

    我的demo是BroadcastReceiver+Service,不用电源管理,但是实现了锁屏时依然运行的功能,如果用电源管理禁止锁屏的话,你的项目一运行,半天手机就没电了
      

  5.   

    你的邮箱是:[email protected]
      

  6.   

    是要开线程去做的。service里不能直接放while(true)
      

  7.   

    楼主能不能也发给我一份,多谢了。[email protected]
      

  8.   

    楼主,demo能不能给我发一份,我也遇到了同样的问题,我想让一个Service一直在后台运行。我邮箱:[email protected]
      

  9.   

    楼主,可以给我发一份吗?这个问题我已经苦恼好久了,邮箱[email protected],谢谢!
      

  10.   

    楼主发我一份吧,谢谢 [email protected]
      

  11.   

    麻烦发我一份:[email protected]   谢谢!
      

  12.   

    麻烦发一份demo给我 谢谢 最近我也遇到这个问题了[email protected]