如果我在 MainActivity 中创建了一个数据库:
RankingDBHelper rankingDBHelper = new RankingDBHelper(this);
mDatabase = rankingDBHelper.getWritableDatabase();
然后在 DialogFragment 中我想将数据添加到数据库中,我应该怎么做呢?
我应该像在 MainActivity 中那样做吗?
RankingDBHelper rankingDBHelper = new RankingDBHelper(this);
mDatabase = rankingDBHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_NAME, name);
contentValues.put(COLUMN_SCORE, score);
contentValues.put(COLUMN_LEVEL, level);
contentValues.put(COLUMN_MULTIPLIER, multiplier);
或者 mDatabase 引用变量应该是静态的吗?
static mDatabase;