I have a splash screen in my app and im triying to check if the tables of my db exist and if not, create the tables that my app needs. My idea is to make 2 checks, something like this:
if(db.exists){
increase the progressbar to the 100%
(If we could add a short pause to the progress bar transition better, just
for a better user experience)}
else{
increase the progress bar to 50% and create databases. By last increase
progress bar to 100%}
start -> main_activity
This just the idea that i have but i dont how to make and i dont how to reference the methods of AppSQLiteHelper.java. If any one of you have a better idea for improve the code logic better. Here is the code that write till the moment:
SplashScreenActivity.java
public class SplashScreenActivity extends Activity {
// Set the duration of the splash screen
public ProgressBar splash_screenProgressBar;
public int MAX_VALUE = 30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set portrait orientation
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.splash_screen);
splash_screenProgressBar = (ProgressBar) findViewById(R.id.splash_screenProgressBar);
splash_screenProgressBar.setMax(MAX_VALUE);
new CountDownTimer(3000, 100) {
int progreso = 1; // Variable que va a ir aumentando del progreso
@Override
public void onTick(long millisUntilFinished) {
splash_screenProgressBar.setProgress(progreso);
progreso += (1);
}
@Override
public void onFinish() {
splash_screenProgressBar.setProgress(MAX_VALUE);
// Start the next activity
Intent mainIntent = new Intent().setClass(SplashScreenActivity.this, MainActivity.class);
startActivity(mainIntent);
// Close the activity so the user won't able to go back this activity pressing Back button
finish();
}
}.start();
}
}
AppSQLiteHelper.java
public class AppSQLiteHelper extends SQLiteOpenHelper{
String sqlCreateCartera = "CREATE TABLE CARTERA (saldo INTEGER)";
String sqlCreateValor = "CREATE TABLE VALOR (cantidad INTEGER, precio_accion INTEGER, entidad TEXT)";
String sqlCreateEstado = "CREATE TABLE ESTADO (estado BOOLEAN)";
public AppSQLiteHelper(Context contexto, String nombre,
CursorFactory factory, int version) {
super(contexto, nombre, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(sqlCreateCartera);
db.execSQL(sqlCreateValor);
db.execSQL(sqlCreateEstado);
}
@Override
public void onUpgrade(SQLiteDatabase db, int versionAnterior, int versionNueva) {
db.execSQL("DROP TABLE IF EXISTS CARTERA");
db.execSQL("DROP TABLE IF EXISTS VALOR");
db.execSQL("DROP TABLE IF EXISTS ESTADO");
db.execSQL(sqlCreateCartera);
db.execSQL(sqlCreateValor);
db.execSQL(sqlCreateEstado);
}
}
Aucun commentaire:
Enregistrer un commentaire