Commit 9be45826697ce068c5852e9f00efe0d9c046f636
1 parent
c7efa41793
Exists in
master
避免版本升级实体类变化导致崩溃
Showing
2 changed files
with
12 additions
and
2 deletions
Show diff stats
app/src/main/java/com/hjx/parent/App.java
libs/common/src/main/java/com/prws/common/utils/SharedPreferencesUtil.java
... | ... | @@ -263,10 +263,19 @@ public class SharedPreferencesUtil { |
263 | 263 | } |
264 | 264 | |
265 | 265 | public static void clear(Context context) { |
266 | - SharedPreferences preferences = context.getSharedPreferences("config", Context.MODE_PRIVATE); | |
267 | - SharedPreferences.Editor editor = preferences.edit(); | |
266 | + SharedPreferences.Editor editor = sp.edit(); | |
268 | 267 | editor.clear(); |
269 | 268 | editor.commit(); |
270 | 269 | } |
271 | 270 | |
271 | + private static final int myVersion = 2; | |
272 | + public static void checkVersion(Context context) { | |
273 | + if (sp.getInt("myVersion", 0) == myVersion) { | |
274 | + return; | |
275 | + } | |
276 | + clear(context); | |
277 | + SharedPreferences.Editor editor = sp.edit(); | |
278 | + editor.putInt("myVersion", myVersion); | |
279 | + editor.apply(); | |
280 | + } | |
272 | 281 | } | ... | ... |