onDowngrade() in SQLiteOpenHelper (or another way to not crash when downgrading)

前端 未结 1 844
旧时难觅i
旧时难觅i 2021-01-19 18:00

Very new to Java. Working with my app, and decided, I\'d drop my DATABASE_VERSION back down to 1 (no real reason).

When I started the app, it crashed, and one of th

1条回答
  •  悲哀的现实
    2021-01-19 18:19

    Is there a way (easy way hopefully) to allow me to change the database version to any number I want and have it still run without crashing immediately?

    In development, simply get rid of your database, either via the Clear Data button for your app in Settings, or by uninstalling the app from settings, or by wiping the whole emulator (if this is an emulator). Your database will be created anew on next run via a call to onCreate() in your SQLiteOpenHelper.

    In production, as rciovati noted, the concept of supporting a downgrade was only introduced with API Level 11, and I have never tried it personally.

    0 讨论(0)
提交回复
热议问题