activity类    public class Main extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_main);
     Intent intent = new Intent(this,WeatherService.class);
     this.startService(intent);
    
        
    }
}服务类:已经注册
public class WeatherService extends Service{
private Thread thread = null;
@Override
public void onCreate() {
thread = new Thread(backgroundWork); System.out.print("测试1................");
         super.onCreate();
} @Override
public void onDestroy() {
super.onDestroy();
} @Override
public void onStart(Intent intent, int startId) {
thread.start(); System.out.print("测试2................");
super.onStart(intent,startId);

}
private Runnable backgroundWork = new Runnable() {

public void run() {
System.out.print("测试3................"); }
}; @Override
public IBinder onBind(Intent arg0) {
return null;
}}
logcat里怎么没有看到上面的一些测试信息呢?

解决方案 »

  1.   

    是不是 Intent intent = new Intent(Activity.this,WeatherService.class);?
    没有错误提示吗?
      

  2.   

     Main   是配置的这个吗?       
    <intent-filter >
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter> 
      

  3.   

    android 2.0后 生命周期onStartCommand()取代了OnStart() ,你需要重写onStartCommand()。另外,想看到log你必须写log.i()而不是System.out.print(),   sysout只会吧信息输出到控制台
      

  4.   

    你的测试打印语句是有问题的:
    Log.e("WeatherService","测试1......");
    然后在LogCat中找WeatherService。看看
      

  5.   

    logcat里也可以看到System.out.print()输出的语句!!!!!