2013-11-10 78 views
0

我正在開發一個應用程序。我在其中使用活動中的工作線程。我的應用程序出現了一些問題,並試圖找出使用調試標記的問題。但logcat不會顯示線程內部的標籤。我是新手,所以不很瞭解的..Logcat不顯示調試標籤

這裏是代碼..

package com.example.forgetmenot; 

import java.util.ArrayList; 
import java.util.Calendar; 

import android.app.Service; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Handler; 
import android.os.IBinder; 
import android.util.Log; 
import android.widget.Toast; 

public class BirthdayService extends Service{ 

    SQLiteDatabase db; 
    BirthdayDatabase myDatabase = new BirthdayDatabase(this, null, null, 0); 
    private ArrayList<String> data = new ArrayList<String>(); 
    Handler handler = new Handler(); 
    String form[] ={"_id","name","contact","day","month","year"}; 
    String TAG = "Debug"; 
    @Override 
    public IBinder onBind(Intent arg0) { 

     return null; 
    } 

    @Override 
    public void onCreate() { 
//  Toast.makeText(this,"birthday Service started", Toast.LENGTH_SHORT).show(); 
     super.onCreate(); 
    } 

    @Override 
    public void onDestroy() { 

     super.onDestroy(); 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Calendar cal = Calendar.getInstance(); 

     new Thread(new Runnable() { 

      @Override 
      public void run() { 
       Calendar cal = Calendar.getInstance(); 
       int mDay = cal.get(Calendar.DAY_OF_MONTH); 
       int mMonth = cal.get(Calendar.MONTH); 
       Log.d(TAG, "Current day: "+mDay); 
       Log.d(TAG,"Current month: "+mMonth); 
       int birthDay = 0; 
       int birthMonth = 0; 
       final Cursor mycursor = db.query("birthdays", form, null, null, null, null, null, null); 
       while(mycursor.moveToNext()){ 
        birthDay = mycursor.getInt(3); 
        birthMonth = mycursor.getInt(4); 
        Log.d(TAG, "birhDay:"+birthDay); 
        Log.d(TAG, "birthMonth:"+birthMonth); 
        if(mDay == birthDay && mMonth == birthMonth) 
        { 
         handler.post(new Runnable() { 

          @Override 
          public void run() { 

           Toast.makeText(getBaseContext(), "Happy Birthday "+mycursor.getString(1), Toast.LENGTH_SHORT).show(); 
          } 

         }); 

         db.close(); 
         break; 
        } 
       } 
       db.close(); 

      } 

     }); 

     Toast.makeText(this, "BirthdayService", Toast.LENGTH_SHORT).show(); 
     return 0; 
    } 

} 

回答

0

開始你在onStartCommand中創建的線程

+0

謝謝老兄,我忘了開始這個線程...多麼幼稚的錯誤。 –

0

,你必須確保在設備信息標籤,其仿真器或設備選擇, 如果你仍然沒有找不到它,然後請重新設置adb,然後請選擇您的模擬器,然後再試一次,

仍然會出現同樣的問題,然後重新啓動您的eclipse或adb。

+0

這是不是問題你在描述什麼。問題在於標籤在工作線程中。以便工作者內部的標籤在logcat中顯示值。 –