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 9143249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:58:34+00:00 2026-06-17T09:58:34+00:00

I am working on an update for my current app. My app use SQLite

  • 0

I am working on an update for my current app. My app use SQLite DB and so far I am at version 1. I will need to alter/introduce new tables in my second version. I did my research and I found that to do that the best way is to have switch(case) statements in which I do the updates to db in a fall-through manner.

My question is, how does android know what is the older version in the onUpgrade()?. In fact, when does it get called?.

So for the users who are downloading my updated app for first time, I assume the onUpgrade() will not be called! How would android know when not to call onUpgrade()?

Please clarify this for me. I want to submit my first update and I don’t want to lose my hard-earned users 🙂

  • 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-17T09:58:35+00:00Added an answer on June 17, 2026 at 9:58 am

    When implementing the SQLiteOpenHelper, you pass a version parameter to the superclass constructor. This should be a static value you can change in future versions of your application (usually you’d want this to be a static final attribute of your SQLiteOpenHelper implementation, alongside the database name you pass to the superclass constructor).

    Then, when you want to update the database, you increment the version parameter that will be used in your SQLiteOpenHelper implementation, and perform the SQL modifications you intend to do, programmatically, inside the onUpgrade() method.

    Say your DB started with table A in version 1, then you added table B in version 2 and table C in version 3, your onUpgrade method would look like:

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion < 2) { // do stuff for migrating to version 2
            db.execSQL( ...create table B... );
        }
        if (oldVersion < 3) { // do stuff for migrating to version 3
            db.execSQL( ...create table C... );
        }
    }
    

    When the superclass constructor runs, it compares the version of the stored SQLite .db file against the version you passed as a parameter. If they differ, onUpgrade() gets called.

    I should check the implementation, but I assume onUpgrade() is also called after onCreate() if the database needs to be created, and there’s a way to ensure all of the upgrades are executed (for example, by forcing all version numbers to be positive integers and initializing a newly created database with version 0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an app update and am building this new version completely
I am new to rails, and working on an internal content management app. I
I am working on a GPS app. My app will fire notification by NotificationManager
I'm working on a live photo stream app. Essentially, users will be uploading photos
My app find out current location using GPS . It is working fine in
We are working on an update system for our software. The updater should run
I am currently working on an update to an iOS application that was released
-edit- nevermind, i made a mistake in my select statement. Update was working correctly.
Update: Got this working by disabling CodeIgniter Profiler which was interfering with the Ajax
UPDATE: This is the working example. First we create a class to hold weekday,

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.