private void readCurrentUser() { dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class); RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao(); SharedPreferences sp = getApplicationContext().getSharedPreferences("SettingInfo", MODE_PRIVATE); mUser = userDao.queryForId(sp.getString("CurrentSchoolNumber", "")); }
public void updateUserDB(String jsonStr) throws Exception { JSONObject data = new JSONObject(jsonStr); JSONObject userStr = data.getJSONObject("User"); Gson gson = new Gson(); User user = gson.fromJson(userStr.toString(), User.class); // 写入user到数据库 dbHelper = OpenHelperManager.getHelper(getApplicationContext(), WTDbHelper.class); RuntimeExceptionDao<User, String> userDao = dbHelper.getUserDao(); userDao.update(user); }