Reputation: 2535
I am trying to implement a foreign key in my database table, for that I need to call onConfigure where I set the PRAGMA. However implementation of this method gives me strange behavior. When I use the @Override annotation the eclipse intellisense asks me to remove it , and when I remove it I get a different set of warnings This method is not overriding anything with the current build target, but will in API level 16 (current target is 11)
Following is my code snippet for the particular problem code:
public static class DatabaseHelper extends SQLiteOpenHelper {
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE0);
db.execSQL(unique);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public void onConfigure(SQLiteDatabase db){
System.out.println("Hello from on Configure");
db.execSQL("PRAGMA foreign_keys=ON");
}
}
This is my Manifest SDK Declaration:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
Upvotes: 0
Views: 578
Reputation: 23638
To stop android lint from raising an error, annotate the onConfigure
override in DatabaseOpenHelper
to be JellyBean or higher. Older
android versions will continue to use the old mechanism already checked
for in the onOpen override.
You need to add the @TargetAPI
in your class as below:
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onConfigure(SQLiteDatabase db) {
super.onConfigure(db); }
Check out the Reference
Upvotes: 2