I have an application that uses an SQL database. This is encapsulated by the SQLiteOpenHelper class. When the splash screen starts, it calls init in the DataProvider class, which stores a protected static instance of SQLiteOpenHelper. init simply calls the SQLiteOpenHelper constructor:
public class UKMPGData extends SQLiteOpenHelper
{
public UKMPGData(Context context, String databaseName)
{
super(context, databaseName, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
onCreate(db);
}
}
public class UKMPGDataProvider
{
protected static UKMPGData uKMpgData;
public static void init(Context aApplicationContext, String aDatabaseName)
{
uKMpgData = new UKMPGData(applicationContext, databaseName);
}
public static void close()
{
uKMpgData.close();
}
}
Then I had two more classes that extended UKMPGDataProvider and therefore had access to uKMpgData. These classes retrieve and store specific types of data from the database. For instance.
public class VehicleDataProvider extends UKMPGDataProvider
{
public static Cursor getVehicles()
{
Cursor cursor = null;
SQLiteDatabase db = uKMpgData.getReadableDatabase();
cursor = db.query(VEHICLE_TABLE_NAME, GET_VEHICLES_FROM_CLAUSE, null, null, null, null, ORDER_BY);
return cursor;
}
}
, , , , , , , , Activity, getVehicles() (. ). , uKMpgData .
, Android , , , , - , ? , SplashScreen , , .
- - ( ), .
, . VehicleDataProvider (UKMPGDataProvider), ukMpgData. , , UKMPGDataProvider, .
,