private void checkForInitData() { int i = 0, num = Constants.NUMBER; int countDb = 0; Cursor cursor; cursor = dbMgr.queryData(Constants.DATA_TABLE, new String[] {"count(*)"}, null); if (cursor != null && 0 != cursor.getCount()) { if (cursor.moveToFirst()) { countDb = cursor.getInt(cursor.getColumnIndex("count(*)")); Log.d(WaterReminderActivity.class.getSimpleName(), "read countDb=" + countDb); } } if (0 == countDb) { ContentValues cv; for (i = 0; i < num; ++i) { cv = new ContentValues(); cv.put("idx", i); cv.put("hour", Constants.DEFAULT_HOUR + 2 * i); cv.put("minute", 0); dbMgr.insertData(Constants.DATA_TABLE, cv); Log.d( WaterReminderActivity.class.getSimpleName(), "insert to " + Constants.DATA_TABLE + ":[" + i + "](" + cv.toString() + ")"); } } for (i = 0; i < num; ++i) { cursor = dbMgr.queryData( Constants.DATA_TABLE, new String[] {"idx", "hour", "minute"}, "idx='" + i + "'"); if (cursor.moveToFirst()) { hour[i] = cursor.getInt(cursor.getColumnIndexOrThrow("hour")); minute[i] = cursor.getInt(cursor.getColumnIndexOrThrow("minute")); p_intent[i] = PendingIntent.getBroadcast(this, i, alarmIntent, 0); Log.d( WaterReminderActivity.class.getSimpleName(), "read data " + Constants.DATA_TABLE + ":[" + i + "](" + hour[i] + ":" + minute[i] + ")"); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.activity_water_reminder); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, // R.layout.titlebar); am = (AlarmManager) getSystemService(ALARM_SERVICE); alarmIntent = new Intent(this, AlarmReceiver.class); dbMgr.open(); checkForInitData(); initReminderView(); }