I'm starting out in java android, I'm quite lay still, I'm catching the POO concept little by little.
My problem is as follows, I have a class BankBank and another BankController where I have some methods to manipulate the bank, this in an activity with name menu, so far everything works.
The question is whether I need to manipulate the bank's data in another activity, which is the correct way to do this.
At first I thought about repeating the class in the other activity but I was afraid to do this: the bank was going to be rewritten and I also found it inelegant to repeat the whole code. So I thought I did not have a way to instantiate this class in the other activity.
Below the code I used to create and manipulate the database, just the basics, I removed the methods to not be extensive.
public class BancoController {
private SQLiteDatabase db;
private CriaBanco banco;
public BancoController(Context context) {
banco = new CriaBanco(context);
}
}
public class CriaBanco extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static final String DB_NAME = "dbcoletor.db";
public CriaBanco(Context context) {
super(context, DB_NAME, null, VERSION);
}
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i2) {
//--nothing for now--
}
}
To solve I created a class in the other activity and I used this form:
private SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase("data/data/com.coletorrc/databases/dbcoletor.db", null);
So I was able to manipulate the bank, although it worked, I was wondering if there would be a more elegant way to do it.