Class that creates the bank
public class CriaBanco extends SQLiteOpenHelper {
private static final String NOME_BANCO = "lista.db";
private static final int VERSAO_BANCO = 1;
public CriaBanco(Context context) {
super(context, NOME_BANCO, null, VERSAO_BANCO);
}
@Override
public void onCreate(SQLiteDatabase db) {
final String SQL_CRIAR_TABELA = "CREATE TABLE lista_notify (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT "+
"hora_notificacao TEXT NOT NULL"+
"texto_notificacao TEXT NOT NULL)";
db.execSQL(SQL_CRIAR_TABELA);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
MainActivity.java where the instance of the class BankAction.java is created
public class MainActivity extends AppCompatActivity {
private EditText ed_hora_notificacao;
private EditText ed_texto_notificacao;
private CriaBanco mDbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CriaBanco banco = new CriaBanco(this);
}}
Method that inserts data into the bank
public void cadastrar_periodic(View v){
SQLiteDatabase db = mDbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("hora_notificacao", "Toto");
values.put("texto_notificacao", "Terrier");
long newRowId = db.insert("lista_notify", null, values);
}
Error text giving
Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.