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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:15:45+00:00 2026-05-23T13:15:45+00:00

I am a bit confused with the android SQLite database handling. I went through

  • 0

I am a bit confused with the android SQLite database handling. I went through tutorials but I didn’t get the exact point.

We can have a database class that extends SQLiteOpenHelper, and can override onCreate() method and create a database.

Upgrading database part is a bit confusing. In the following method, how to handle the verions
onUpdate(SQLiteDatabase db,int old Version,int newVerison)

Does it mean that when the first time we create database the version is 1. Then, once modified the version become 2.
Then if we want to modify again
old Version = 2, newVerison = 3
[onUpdate(SQLiteDatabase db,int old Version,int newVerison) ]

This method will be execute when we pass the constructor version as in the following code (as 2)

public DatabaseHelper(Context context) {
  super(context, dbName, null,2);
}

I need to know whether when we need to call onUpgrade() method should we pass version as 2 always or we have to increase one every time for the previous version.

  • 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-05-23T13:15:45+00:00Added an answer on May 23, 2026 at 1:15 pm

    Increment your database version every time the schema changes.

    You never need to call onUpgrade directly. Android will call it when required when you open the database by comparing the version of the database with the version that your code is specifying as the current version.

    You just need to handle the upgrade process in onUpgrade – it might go something like this:

    int curVer = oldVersion;
    while ( curVer < newVersion ) {
        curVer++;
        switch ( curVer ) {
            case 2: {
                // Upgrade from V1 to V2
                break;
            }
            case 3: {
                // Upgrade from V2 to V3
                break;
            }
            case 4: {
                // Upgrade from V3 to V4
                break;
            }
        }
    }
    

    Lets say your newVersion is 4 and oldVersion is 1 – first iteration will increment curVer to 2 and will run the V2 to V3 upgrade code. Second iteration increments curVer to 3 and runs the V2 to V3 upgrade code, final iteration increments curVer to 4 and runs the V3 to V4 upgrade code.

    This works for all values of oldVersion that are less than newVersion. and will sequentially upgrade through the intermediate versions if your users are skipping upgrades of the app.

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

Sidebar

Related Questions

Bit confused here, I have an on-demand instance but do I get charged even
I'm a bit confused here. Microsoft as far as I can tell claims that
I'm a bit confused from what I've heard Java doesn't do events. But I
Little bit confused... I am trying to track mailto links being clicked, but constantly
I'm a bit confused about how you can or cannot make crossdomain ajax requests
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused that the argument to crypto functions is a string. Should
I am a bit confused why this code compiles. I leave out the necessary
I'm fairly new to the Zend Framework and MVC and I'm a bit confused

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.