Thanks guys for your kind reply :) On 4월27일, 오전11시32분, Emanuel Moecklin <[email protected]> wrote: > I'm running the database initialization in an IntentService which > always runs in a separate thread. > The main activity starts the service and connects to the service to > show a progress bar. > If the main activity is shut down the service continues to run. > If you restart the main activity it reconnects to the service and > shows the progress bar again. > The main difficulty with this approach is to prevent the service from > being started twice (IntentServices queue the Intents an run them > sequentially). > I solved this by checking & setting a SharedPreferences value that > indicates whether the initialization has finished or not. The Service > won't run if it has been previously started. > > I guess that you load the database by sql inserts. > I used to do that too but a much faster solution is to include a > preloaded database in the asset folder and extract it to phone memory > during initialization. > This approach works fine if you extract to phone memory and not > sdcard. I used to do the latter too but sdcard seems to be too > unreliable on some phones and I got too many SQLException crash > reports so I reverted back to copying the db to phone memory. > One nice side effect of this approach is that the apk will be much > smaller (provided the asset database is zipped). > > Cheers > Emanuel Moecklin > 1gravity LLC > > On Apr 26, 2:37 am, Javacoffee <[email protected]> wrote: > > > > > Hi guys, > > > I'm implementing the app requires database set-up when installed for > > the first time. > > > It works fine however it takes a couple of minutes wait with black > > screen (default screen) while establishing database. > > > I understand that is necessary but would like to treat more elegant > > approach for User Interface. > > > I'm using DatabaseHelper class inherited from SQLiteOpenHelper to > > initiate database for the first time. > > > Here is snippet for your understanding. > > > ================================================ > > private static class DatabaseHelper extends SQLiteOpenHelper > > > { > > private Context dbContext; > > > DatabaseHelper(Context context) > > { > > super(context, DATABASE_NAME, null, > > DATABASE_VERSION); > > dbContext = context; > > } > > > @Override > > public void onCreate(SQLiteDatabase db) > > { > > db.execSQL(DATABASE_CREATE); > > ContentValues values = new ContentValues(); > > loadDB(db, values); > > } > > > @Override > > public void onUpgrade(SQLiteDatabase db, int oldVersion, int > > newVersion) > > { > > Log.w(TAG, "Upgrading from " + oldVersion + " to " > > + newVersion); > > db.execSQL(DATABASE_DROP); > > onCreate(db); > > } > > > private void loadDB(SQLiteDatabase db, ContentValues values) > > { > > // establishing database here. > > // it takes a couple of minutes but would like > > to handle with more elegant way. > > } > > > } > > > ==================================================================== > > > loadDB() method needs operation with more sophisticated approach so > > any idea or advise will be welcome. > > > Thanks.- 원본 텍스트 숨기기 - > > - 원본 텍스트 보기 -
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

