码迷,mamicode.com
首页 > 数据库 > 详细

关于OTA升级从高版本到低版本升级后,数据库无法降级引起的异常分析

时间:2015-01-15 14:19:50      阅读:384      评论:0      收藏:0      [点我收藏+]

标签:

1.问题描述:
OTA升级从高版本升级到低版本成功,开机后桌面闹钟图标不见了,且桌面闹钟报错,无法打开应用。

参考log如下:
01-14 20:29:22.290: E/AndroidRuntime(2722): FATAL EXCEPTION: AsyncHandler
01-14 20:29:22.290: E/AndroidRuntime(2722): Process: com.android.deskclock, PID: 2722
01-14 20:29:22.290: E/AndroidRuntime(2722): android.database.sqlite.SQLiteException: Can‘t downgrade database from version 10 to 7
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.database.sqlite.SQLiteOpenHelper.onDowngrade(SQLiteOpenHelper.java:361)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:255)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
01-14 20:29:22.290: E/AndroidRuntime(2722): at com.android.deskclock.provider.ClockProvider.query(ClockProvider.java:96)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.content.ContentProvider.query(ContentProvider.java:922)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.content.ContentProvider$Transport.query(ContentProvider.java:213)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.content.ContentResolver.query(ContentResolver.java:462)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.content.ContentResolver.query(ContentResolver.java:405)
01-14 20:29:22.290: E/AndroidRuntime(2722): at com.android.deskclock.provider.AlarmInstance.getInstances(AlarmInstance.java:188)
01-14 20:29:22.290: E/AndroidRuntime(2722): at com.android.deskclock.alarms.AlarmStateManager.FixAlarmInstancesForReboot(AlarmStateManager.java:684)
01-14 20:29:22.290: E/AndroidRuntime(2722): at com.android.deskclock.AlarmInitReceiver$1.run(AlarmInitReceiver.java:102)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.os.Handler.handleCallback(Handler.java:808)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.os.Handler.dispatchMessage(Handler.java:103)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.os.Looper.loop(Looper.java:193)
01-14 20:29:22.290: E/AndroidRuntime(2722): at android.os.HandlerThread.run(HandlerThread.java:61)

2.分析结果:
    从上面的log中可以看到,此类异常由数据库无法将降级导致,此时恢复出厂设置可以恢复正常。

3.解决方案

      可通过在DatabaseHelper.java重写父类SQLiteOpenHelper.java的onDowngrade()方法来规避该问题,或者直接在SQLiteOpenHelper.java中对该方法就行修改。

 public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
     throw new SQLiteException("Can‘t downgrade database from version " +
             oldVersion + " to " + newVersion);
 }




关于OTA升级从高版本到低版本升级后,数据库无法降级引起的异常分析

标签:

原文地址:http://blog.csdn.net/huangyabin001/article/details/42740147

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!