我正在開發一個應用程序。我在其中使用活動中的工作線程。我的應用程序出現了一些問題,並試圖找出使用調試標記的問題。但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;
}
}
謝謝老兄,我忘了開始這個線程...多麼幼稚的錯誤。 –