I have created a SQLiteOpenHelper object in MainActivity:
public class ExchangeActivity extends AppCompatActivity {
public CurrencyDBHelper db;
private Handler handler;
private int delay = 30000;
private DataHandler dataHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
//create CurrencyDBHelper object
db = new CurrencyDBHelper(this);
Log.v("DBTag", "DB created");
//Activity and UI
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exchange);
}}
My CurrencyDBHelper class code:
public class CurrencyDBHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "LastCurrency.db";
//constructor
public CurrencyDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE CURRENCY ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "NAME TEXT, "
+ "RATE REAL); ");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
I need to call the db
from the other class. How can I do this from the other class?
I tryed to create SQLiteOpenHelper not in MainActivity, but it does not work for me. It seems like I have to use Context, but I dont undestand hot do this.
Please help. Thanks!