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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:05:11+00:00 2026-06-04T07:05:11+00:00

I meet a problem when read the source code of Android 2.2 default Launcher.

  • 0

I meet a problem when read the source code of Android 2.2 default Launcher.
the source code segment of LauncherProvider.DatabaseHelper:

@Override
public void onCreate(SQLiteDatabase db) {
    if (LOGD)
    Log.d(TAG, "creating new launcher database");

    db.execSQL("CREATE TABLE favorites (" + "_id INTEGER PRIMARY KEY,"
        + "title TEXT," + "intent TEXT," + "container INTEGER,"
        + "screen INTEGER," + "cellX INTEGER," + "cellY INTEGER,"
        + "spanX INTEGER," + "spanY INTEGER," + "itemType INTEGER,"
        + "appWidgetId INTEGER NOT NULL DEFAULT -1,"
        + "isShortcut INTEGER," + "iconType INTEGER,"
        + "iconPackage TEXT," + "iconResource TEXT," + "icon BLOB,"
        + "uri TEXT," + "displayMode INTEGER" + ");");

    // Database was just created, so wipe any previous widgets
    if (mAppWidgetHost != null) {
    mAppWidgetHost.deleteHost();
    sendAppWidgetResetNotify();
    }

    if (!convertDatabase(db)) {
    // Populate favorites table with initial favorites
    loadFavorites(db);
    }
}

private boolean convertDatabase(SQLiteDatabase db) {
    if (LOGD)
    Log.d(TAG,
        "converting database from an older format, but not onUpgrade");
    boolean converted = false;

    final Uri uri = Uri.parse("content://" + Settings.AUTHORITY
        + "/old_favorites?notify=true");
    final ContentResolver resolver = mContext.getContentResolver();
    Cursor cursor = null;

    try {
    cursor = resolver.query(uri, null, null, null, null);
    } catch (Exception e) {
    // Ignore
    }

    // We already have a favorites database in the old provider
    if (cursor != null && cursor.getCount() > 0) {
    try {
        converted = copyFromCursor(db, cursor) > 0;
    } finally {
        cursor.close();
    }

    if (converted) {
        resolver.delete(uri, null, null);
    }
    }

    if (converted) {
    // Convert widgets from this import into widgets
    if (LOGD)
        Log.d(TAG, "converted and now triggering widget upgrade");
    convertWidgets(db);
    }

    return converted;
}

onCreate() is called to create database when there is no database in system. At the tail of onCreate(), it calls convertDatabase(SQLiteDatabase db). And there have query codes in convertDatabase(SQLiteDatabase db).I am confused. Why it query in onCreate()? when convertDatabase(SQLiteDatabase db) will return true? My Android version is 2.2

  • 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-04T07:05:12+00:00Added an answer on June 4, 2026 at 7:05 am

    Some context can be retrieved from log messages:

    if (LOGD) Log.d(TAG, "converting database from an older format, but not onUpgrade");
    

    If there was a database in old format, convertDatabase() copies all entries to the new one using copyFromCursor where cursor points to the old instance and then deletes it. So the method will return true if it has found and converted an instance of the database in the old format and false otherwise.

    As the launcher actually called Launcher2 most likely it tries to find traces of the predecessor.

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

Sidebar

Related Questions

I am using Mac OS 10.6.5, g++ 4.2.1. And meet problem with following code:
I meet a problem like this: UPDATE class A { public: A(){} int i;
I meet a problem today. As following. I create a generic Form , public
i'm beginning to learn android, i meet a problem in my project, in my
I meet a headache problem. there are too many Quotation marks in my code
I meet a weired problem when I use maven. I execute the following code
I meet a weired problem when using JUnit in multi-thread environment. The following code
I meet a problem yesterday. Maybe it's because it is April 1st... but it
I meet some scala code with ? but do not know what it mean
I meet this problem when implementing my own swap() method with Python def swap(a,b):

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.