말년
118
2017-09-13 21:45:07.0 작성 2017-09-13 22:02:55.0 수정됨
0
118

안드로이드 왜 onCreate()가 호출이 안되는 걸까요?


public class GroupListHelper extends SQLiteOpenHelper{
    private static final String LOG_TAG = "GroupListHelper";

    private static GroupListHelper        mGroupListHelper;

    public static GroupListHelper getInstance(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)
    {
        if (mGroupListHelper == null)
            mGroupListHelper = new GroupListHelper(context, name, factory, version);

        return mGroupListHelper;
    }

    public GroupListHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version){
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE GROUP_LIST( group_name TEXT PRIMARY KEY)");
        db.execSQL("CREATE TABLE DEVICE_LIST( deviceID INTEGER PRIMARY KEY, group TEXT, lastUpdateTime INTEGER");
        db.execSQL("INSERT INTO GROUP_LIST VALUES ('미등록');");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public boolean isExist(String device){
        int count=0;
        String query = String.format("select count(*) from DEVICE_LIST where deviceID='%s';", device);
        Log.d(LOG_TAG, query);

        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.rawQuery(query, null);

        cursor.moveToFirst();
        count = cursor.getInt(0);

        cursor.close();
        db.close();

        if(count == 0)
            return false;
        else
            return true;
    }

getReadableDatabase()가 호출됐을 때 테이블이 없으면 onCreate()가 호출된다고하는데 디버깅 돌려면 
그냥 넘어갑니다.
0
0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.