0

我正在开发一个应用程序。我在活动中使用工作线程。我的应用程序有一些问题,并尝试使用调试标签找出问题所在。但 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;
    }

}
4

2 回答 2

0

you have to ensure that which emulator or device selected in device info tab, if still you did't find it, then please reset adb, and then please select your emulator, and try again,

still get same problem then restart your eclipse or adb.

于 2013-11-10T07:41:37.697 回答
0

启动您在 onStartCommand 中创建的线程

于 2013-11-10T08:03:32.150 回答