注册service:
<service android:enabled="true" android:name=".service.FirstService"></service>启动service:
public void onClick(View v) 
{
// TODO Auto-generated method stub
System.out.println("onClick");
Intent intent = new Intent();
intent.setClass(testService.this, FirstService.class);
startService(intent);
System.out.println("after startService");
}public void onCreate() 
{
// TODO Auto-generated method stub
System.out.println("onCreate");
super.onCreate();
}public void onStart(Intent intent, int startId) 
{
// TODO Auto-generated method stub
System.out.println("onStart");
super.onStart(intent, startId);}编译,运行都没有错,但就是不能打印出“onCreate”和“onStart”。不能启动service

解决方案 »

  1.   

    你是在DDMS的Logcat里查看的么?
    另外android里一般用Log.d()来输出调试信息。
      

  2.   


    是呀,Android一般都是用Log来打印输出日志的~~
      

  3.   

    System.out.println( "onCreate "); 打到哪里去了你知道不 你也看不到呀
    用Logcat
      

  4.   

    用Log.d("", "")输出log,在Logcat下面查看log输出。
      

  5.   

     你在 activity里怎么搞的?
      

  6.   

    已经解决了,是因为service所在的类和这个activity不在同一个package.