English 中文(简体)
获取关于软件不同版本的持续信息
原标题:Retaining persistent information on different versions of the software
  • 时间:2010-08-31 11:44:56
  •  标签:
  • android

我计划撰写一个免费版本和一个软件的完整版本。 我希望软件的自由版本所储存的信息也能从完整版本中获取(我不想使用内容提供者)。 我也希望确保软件更新时不会丢失这一数据。 我如何做到这一点?

最佳回答

你们需要以明智的方式提升你的助手。

您应始终拥有新的表格编制问题,并使用这一系统更新和转让任何现有数据。 注:上等值方法一度用于你的粉碎机助器,需要处理所有表格。

www。un。org/Depts/DGACM/index_spanish。htm 因此,建议升级:

  • beginTransaction
  • run a table creation with if not exists (we are doing an upgrade, so the table might not exists yet, it will fail alter and drop)
  • put in a list the existing columns List<String> columns = DBUtils。GetColumns(db, TableName);
  • backup table (ALTER table " + TableName + " RENAME TO temp_" + TableName)
  • create new table (the newest table creation schema)
  • get the intersection with the new columns, this time columns taken from the upgraded table (columns。retainAll(DBUtils。GetColumns(db, TableName));)
  • restore data (String cols = StringUtils。join(columns, ","); db。execSQL(String。format( "INSERT INTO %s (%s) SELECT %s from temp_%s", TableName, cols, cols, TableName)); )
  • remove backup table (DROP table temp_" + TableName)
  • setTransactionSuccessful

(如果你重新命名一栏,本末处理下级表,你不会因为栏目名称不匹配而转移现有数据)。

public static List<String> GetColumns(SQLiteDatabase db, String tableName) {
    List<String> ar = null;
    Cursor c = null;
    try {
        c = db。rawQuery("select * from " + tableName + " limit 1", null);
        if (c != null) {
            ar = new ArrayList<String>(Arrays。asList(c。getColumnNames()));
        }
    } catch (Exception e) {
        Log。v(tableName, e。getMessage(), e);
        e。printStackTrace();
    } finally {
        if (c != null)
            c。close();
    }
    return ar;
}

public static String join(List<String> list, String delim) {
    StringBuilder buf = new StringBuilder();
    int num = list。size();
    for (int i = 0; i < num; i++) {
        if (i != 0)
            buf。append(delim);
        buf。append((String) list。get(i));
    }
    return buf。toString();
}
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...