Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7708195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:32:58+00:00 2026-06-01T00:32:58+00:00

I have an app that creates a SQLite database ( with 24 records ),

  • 0

I have an app that creates a SQLite database ( with 24 records ), I am noticing that when I load the app for the first time it takes it a few to actually load the main view, and I assume it is because the app is creating the database for the first time. Here is what it’s doing.
1.) Shows Splash Screen
2.) Blank screen – not programmed in or in any layout, this is where it’s creating the database, again I assume
3.) Shows Main layout – goal

I would love to figure out the best way to display a progress bar during the blank screen, if possible maybe by counting the inserts of the database, not really sure here.

Here is my code

SplashActivity.java

package com.ondrovic.boombozzpassport;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class SplashActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    SplashHandler sHandler = new SplashHandler();
    setContentView(R.layout.splash);

    Message msg = new Message();
    msg.what = 0;
    sHandler.sendMessageDelayed(msg, 3000);

}

private class SplashHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        default:
            break;
        case 0:
            super.handleMessage(msg);

            startActivity(new Intent(getApplicationContext(), MainActivity.class));
            SplashActivity.this.finish();
        }
    }
}
 }

Database.java

 package com.ondrovic.boombozzpassport;

 import java.io.ByteArrayOutputStream;
 import java.io.IOException;

 import android.content.ContentValues;
 import android.content.Context;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.provider.BaseColumns;
 import android.util.Log;

 public class Database extends SQLiteOpenHelper implements BaseColumns {
private final static String DB_NAME = "boombozz.db";
private final static int DB_VERSION = 1;
static final String TABLE_BEERS = "beers";
static final String COL_NAME = "name";
static final String COL_BREWER = "brewer";
static final String COL_ABV = "abv";
static final String COL_RATE = "rating";
static final String COL_BDESC = "breifdescription";
static final String COL_FDESC = "fulldescription";
static final String COL_TYPE = "type";
static final String COL_PIC = "picture";

private Context mContext;

public Database(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
    mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
    Log.w("onCreate : ","Creating Database Version: " + DB_VERSION);
    db.execSQL("CREATE TABLE beers (" + "_id INTEGER PRIMARY KEY, "
            + "name TEXT, " + "brewer TEXT, " + "abv REAL, "
            + "rating REAL, " + "breifdescription TEXT, "
            + "fulldescription TEXT, " + "type TEXT, " + "picture BLOB);");

    Log.w("onCreate","Inserting records into database");

    addBeer(db, "NAME 1", "BREWER 1", "TYPE 1", "BDESC 1", "FDESC 1", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 2", "BREWER 2", "TYPE 2", "BDESC 2", "FDESC 2", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 3", "BREWER 3", "TYPE 3", "BDESC 3", "FDESC 3", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 4", "BREWER 4", "TYPE 4", "BDESC 4", "FDESC 4", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 5", "BREWER 5", "TYPE 5", "BDESC 5", "FDESC 5", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 6", "BREWER 6", "TYPE 6", "BDESC 6", "FDESC 6", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 7", "BREWER 7", "TYPE 7", "BDESC 7", "FDESC 7", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 8", "BREWER 8", "TYPE 8", "BDESC 8", "FDESC 8", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 9", "BREWER 9", "TYPE 9", "BDESC 9", "FDESC 9", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 10", "BREWER 10", "TYPE 10", "BDESC 10", "FDESC 10", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 11", "BREWER 11", "TYPE 11", "BDESC 11", "FDESC 11", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 12", "BREWER 12", "TYPE 12", "BDESC 12", "FDESC 12", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 13", "BREWER 13", "TYPE 13", "BDESC 13", "FDESC 13", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 14", "BREWER 14", "TYPE 14", "BDESC 14", "FDESC 14", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 15", "BREWER 15", "TYPE 15", "BDESC 15", "FDESC 15", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 16", "BREWER 16", "TYPE 16", "BDESC 16", "FDESC 16", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 17", "BREWER 17", "TYPE 17", "BDESC 17", "FDESC 17", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 18", "BREWER 18", "TYPE 18", "BDESC 18", "FDESC 18", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 19", "BREWER 19", "TYPE 19", "BDESC 19", "FDESC 19", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 20", "BREWER 20", "TYPE 20", "BDESC 20", "FDESC 20", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 21", "BREWER 21", "TYPE 21", "BDESC 21", "FDESC 21", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 22", "BREWER 22", "TYPE 22", "BDESC 22", "FDESC 22", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 23", "BREWER 23", "TYPE 23", "BDESC 23", "FDESC 23", 0, 0, R.drawable.beer1);
    addBeer(db, "NAME 24", "BREWER 24", "TYPE 24", "BDESC 24", "FDESC 24", 0, 0, R.drawable.beer1);

}

private void addBeer(SQLiteDatabase db, String name, String brewer,
        String type, String bdesc, String fdesc, int abv, int rate, int icon) {
    final ContentValues cv = new ContentValues();
    cv.put(COL_NAME, name);
    cv.put(COL_BREWER, brewer);
    cv.put(COL_TYPE, type);
    cv.put(COL_BDESC, bdesc);
    cv.put(COL_FDESC, fdesc);
    cv.put(COL_ABV, abv);
    cv.put(COL_RATE, rate);

    final Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), icon);
    writeBitmap(cv, COL_PIC, bitmap);

    db.insert(TABLE_BEERS, null, cv);
}

static void writeBitmap(ContentValues cv, String name, Bitmap bitmap) {
    if (bitmap != null) {

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.flush();
            out.close();

            cv.put(name, out.toByteArray());
        } catch (IOException e) {
            // Ignore
        }
    }

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    Log.w("onUpgrade", "Upgrading database from version: " + oldVersion
            + " to version: " + newVersion);
    db.execSQL("DROP TABLE IF EXISTS beers");
}
 }

MainActivity.java

 package com.ondrovic.boombozzpassport;

 import java.util.concurrent.atomic.AtomicBoolean;

 import com.pushlink.android.PushLink;

 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
 import android.widget.CursorAdapter;
 import android.widget.ListView;
 import android.widget.RatingBar;
 import android.widget.TextView;

 public class MainActivity extends Activity {

AtomicBoolean isActive = new AtomicBoolean(true);

BeerAdapter adapter = null;
Cursor model = null;

SQLiteDatabase db = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PushLink.start(this, R.drawable.ic_launcher, 10, "269f78b325ebda1c", true);

    setContentView(R.layout.main);

    db = (new Database(this)).getWritableDatabase();

    ListView list = (ListView) findViewById(R.id.ListViewBeers);

    model = Beer.getAll(db);
    startManagingCursor(model);
    adapter = new BeerAdapter(model);
    list.setAdapter(adapter);
    list.setOnItemClickListener(onListClick);
}

private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
        startActivity(new Intent(getApplicationContext(), BeerForm.class).putExtra(BeerForm.INTENT_BEER_ID, String.valueOf(id)));
    }
};

@Override
public void onPause() {
    super.onPause();
    isActive.set(false);
}

@Override
public void onResume() {
    super.onResume();
    isActive.set(true);
}

@Override
public void onDestroy() {
    super.onDestroy();
    isActive.set(false);
    db.close();
}
class BeerAdapter extends CursorAdapter {

    public BeerAdapter(Cursor c) {
        super(MainActivity.this, c);
    }

    @Override
    public void bindView(View row, Context ctxt, Cursor c) {
        BeerWrapper wrapper = (BeerWrapper)row.getTag();
        wrapper.populateFrom(c);
    }

    @Override
    public View newView(Context context, Cursor c, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.row, parent, false);
        BeerWrapper wrapper = new BeerWrapper(row);

        row.setTag(wrapper);
        wrapper.populateFrom(c);

        return row;
    }
}

class BeerWrapper {

    private TextView name = null;
    private TextView brewer = null;
    private TextView bdesc = null;
    private RatingBar rating = null;
    private View row = null;

    BeerWrapper(View row) {
        this.row = row;
    }

    void populateFrom(Cursor c) {
        getName().setText(c.getString(c.getColumnIndex("name")));
        getBrewer().setText(c.getString(c.getColumnIndex("brewer")));
        getDesc().setText(c.getString(c.getColumnIndex("breifdescription")));
        getRating().setRating(c.getFloat(c.getColumnIndex("rating")));

    }

    TextView getName() {
        if (name == null) {
            name = (TextView)row.findViewById(R.id.TextViewRowName);
        }
        return name;
    }

    TextView getBrewer() {
        if (brewer == null) {
            brewer = (TextView)row.findViewById(R.id.TextViewRowBrewer);
        }
        return brewer;
    }

    TextView getDesc() {
        if (bdesc == null) {
            bdesc = (TextView)row.findViewById(R.id.TextViewRowBriefDescription);
        }
        return bdesc;
    }

    RatingBar getRating() {
        if (rating == null) {
            rating = (RatingBar)row.findViewById(R.id.RatingBarRatingSmall);
        }
        return rating;
    }
}
 }

Not sure the best place to put this or how to correctly implement to only show up when the database is created. Any ideas or suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T00:32:59+00:00Added an answer on June 1, 2026 at 12:32 am

    Okay so I decided to change the whole process and ended up going with an AsyncTask that downloads the file from my site and stores it on the SD card. I am then just opening that database and all seems to work faster, it shows the progress dialog while downloading the file. For anyone that is interested here is the code:

    Note: you have to already have created your database prior to this.

    Downloader.java

     package com.ondrovic.downloader;
    
     import java.io.File;
     import java.io.FileOutputStream; 
     import java.io.InputStream;
     import java.net.HttpURLConnection;
     import java.net.URL;
    
     import android.app.Activity;
     import android.app.Dialog;
     import android.app.ProgressDialog;
     import android.content.Intent;
     import android.database.SQLException;
     import android.database.sqlite.SQLiteDatabase;
     import android.os.AsyncTask;
     import android.os.Bundle;
     import android.os.Environment;
     import android.util.Log;
    
     public class Downloader extends Activity {
    SQLiteDatabase db = null;
    public static final String LOG_TAG = "DOWNLOADER";
    private ProgressDialog bar;
    public static final int PROGRESS = 0;
    
    File rDIR = Environment.getExternalStorageDirectory();
    
    public String fDIR = "<location you want to store file on SD card>";
    public String fNAME = "<your database.db>";
    public String fURL = "<your url>";
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
    
        checkDB();
    
    
            //DIRExists(fDIR);
            //new Download().execute(fURL);
    }
    
    class Download extends AsyncTask <String, String, String> {
    
        @Override
        public void onPreExecute() {
            super.onPreExecute();
            showDialog(PROGRESS);
        }
    
        @Override
        protected String doInBackground(String... aurl) {
    
            try {
                URL url = new URL(fURL);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setRequestMethod("GET");
                con.setDoOutput(true);
                con.connect();
    
                int fSIZE = con.getContentLength();
    
                FileOutputStream out = new FileOutputStream(new File(rDIR + fDIR, fNAME));
    
                InputStream in = con.getInputStream();
    
                byte[] buffer = new byte[1024];
                int len = 0;
                long total = 0;
    
                while ((len = in.read(buffer)) > 0) {
                    total += len;
                    publishProgress("" + (int)((total*100)/fSIZE));
                    out.write(buffer, 0, len);
                }
                out.close();
            } catch (Exception e) {
                Log.d(LOG_TAG, e.getMessage());
            }
    
            return null;
        }
    
        protected void onProgressUpdate(String... progress) {
    
            Log.d(LOG_TAG, progress[0]);
            bar.setProgress(Integer.parseInt(progress[0]));
        }
    
        @Override
        protected void onPostExecute(String unused) {
    
            dismissDialog(PROGRESS);
            startActivity(new Intent(getApplicationContext(), Main.class));
            Downloader.this.finish();
        }
    }
    
    public void DIRExists(String dirName) {
    
        File nDIR = new File(rDIR + dirName);
        if (!nDIR.exists()) {
            nDIR.mkdirs();
        }
    }
    
    private boolean checkDB() {
    
        try {
    
            db = SQLiteDatabase.openDatabase(rDIR + fDIR + fNAME, null,
                    SQLiteDatabase.OPEN_READONLY);
            db.close();
            startActivity(new Intent(getApplicationContext(), Main.class));
            Downloader.this.finish();
        } catch (SQLException sqle) {
            Log.d(LOG_TAG, sqle.getMessage());
            DIRExists(fDIR);
            new Download().execute(fURL);
        }
    
        return db != null;
    }
    
    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case PROGRESS:
            bar = new ProgressDialog(this);
            bar.setTitle("Database");
            bar.setMessage("Downloading database...");
            bar.setIndeterminate(false);
            bar.setMax(100);
            bar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            bar.setCancelable(false);
            bar.show();
    
            return bar;
        default:
            return null;
        }
    }
    }
    

    And then you would just access it by doing the following:

    db = SQLiteDatabase.openDatabase(<file location on sd card>, null, SQLiteDatabase.OPEN_READWRITE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that uses an sqlite database. Currently I have a database
I have an app that creates a database and do some stuff. I am
I have an app that creates a variable number of ScatterviewItems based on which
I have a service app that creates AppDomain's during the course of its use
I have a PHP app that creates a CSV file which is forced to
I have a third-party app that creates HTML-based reports that I need to display.
In my Silverlight app I have an event handler that dynamically creates a new
I have a relatively extensive sqlite database that I'd like to import into my
i am creating an app that needs a database. i created it using sqlite
I wanted auto completion feature in ipad app. I have a sqlite database of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.