- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need:
getWritableDatabaseandgetReadableDatabase. Those methods return a Database object on which you can execute queries. From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
EDIT - how to pass in the arraylist to your SQLiteOpenHelper:
class DatabaseHelper extends SQLiteOpenHelper {
List columns;
public AccountsDatabaseHelper(Context context, List columns) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.columns = columns;
}
...
}
Code in the activity:
...
DatabaseHelper helper = new DatabaseHelper(this, myArrayList);
helper.getWriteableDatabase(); //This will execute the onCreate
...
- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
EDIT - how to pass in the arraylist to your SQLiteOpenHelper:
class DatabaseHelper extends SQLiteOpenHelper {
List columns;
public AccountsDatabaseHelper(Context context, List columns) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.columns = columns;
}
...
}
Code in the activity:
...
DatabaseHelper helper = new DatabaseHelper(this, myArrayList);
helper.getWriteableDatabase(); //This will execute the onCreate
...
Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need:
getWritableDatabaseandgetReadableDatabase. Those methods return a Database object on which you can execute queries.From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
EDIT - how to pass in the arraylist to your SQLiteOpenHelper:
class DatabaseHelper extends SQLiteOpenHelper {
List columns;
public AccountsDatabaseHelper(Context context, List columns) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.columns = columns;
}
...
}
Code in the activity:
...
DatabaseHelper helper = new DatabaseHelper(this, myArrayList);
helper.getWriteableDatabase(); //This will execute the onCreate
...
- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
EDIT - how to pass in the arraylist to your SQLiteOpenHelper:
class DatabaseHelper extends SQLiteOpenHelper {
List columns;
public AccountsDatabaseHelper(Context context, List columns) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.columns = columns;
}
...
}
Code in the activity:
...
DatabaseHelper helper = new DatabaseHelper(this, myArrayList);
helper.getWriteableDatabase(); //This will execute the onCreate
...
- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.
EDIT - how to pass in the arraylist to your SQLiteOpenHelper:
class DatabaseHelper extends SQLiteOpenHelper {
List columns;
public AccountsDatabaseHelper(Context context, List columns) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.columns = columns;
}
...
}
Code in the activity:
...
DatabaseHelper helper = new DatabaseHelper(this, myArrayList);
helper.getWriteableDatabase(); //This will execute the onCreate
...
- Implementing SQLiteOpenHelper "provides" two main methods for you to override: onCreate and onUpgrade. onCreate will be called automatically the first time that you create an instance of the helper, and only if the database doesn't exist yet. It's in the onCreate where you execute your create statements.
Then you can use this helper object to get an instance of the database, either a readable or a writable one, depending on what you need: getWritableDatabase and getReadableDatabase. Those methods return a Database object on which you can execute queries.
- From here, you can either wrap the helper in a super class or just add your query/insert/remove/update methods to the helper. These will take a readable or writeable instance and, say, insert the List of whatever that you're trying to add. Intents are not necessary here, you will get the Helper/Wrapper instance directly and perform your operations there.