1버튼을 눌렀을시 메인액티비티 내부에 있는 헬퍼클래스를 호출하여
데이터를 주기적으로 insert해주려 합니다.
반복은 TimerTask를 이용했는데요. run함수 안에 클래스를 호출하려 하는데
this에서 빨간줄이 갑니다. 어떻게 변경 해야할지 질문을 드립니다.
public void OnButton1Clicked(View v) {
mTask = new TimerTask() {
@Override
public void run() {
dbHelper = new DatabaseHelper(DatabaseHelper.this);
db = dbHelper.getWritableDatabase();
db.close();
}
};
mTimer = new Timer();
mTimer.scheduleAtFixedRate(mTask, 0, 1000);
}
private class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
}
public void onOpen(final SQLiteDatabase db) {
println("opened database [" + DATABASE_NAME + "].");
println("creating table [" + TABLE_NAME + "].");
String CREATE_SQL = "create table " + TABLE_NAME + "("
+ "_id integer PRIMARY KEY AUTOINCREMENT,"
+ "bunho TEXT,"
+ "calendar TEXT, "
+ "lat TEXT, "
+ "lng TEXT)";
try {
db.execSQL(CREATE_SQL);
} catch (Exception ex) {
Log.e(TAG, "Exception in CREATE_SQL", ex);
}
println("inserting records.");
try {
db.execSQL("insert into " + TABLE_NAME + "(bunho, calendar, lat, lng) VALUES ('" + phoneNum + "', '" + today + "','" + Lati + "','" + Longi + "');");
} catch (Exception ex) {
Log.e(TAG, "Exception in insert SQL", ex);
}
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ".");
try {
String DROP_SQL = "drop table if exists " + TABLE_NAME;
db.execSQL(DROP_SQL);
} catch (Exception ex) {
Log.e(TAG, "Exception in DROP_SQL", ex);
}
}
}