本文整理匯總了Java中org.litepal.crud.callback.SaveCallback類的典型用法代碼示例。如果您正苦於以下問題:Java SaveCallback類的具體用法?Java SaveCallback怎麽用?Java SaveCallback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SaveCallback類屬於org.litepal.crud.callback包,在下文中一共展示了SaveCallback類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getListener
import org.litepal.crud.callback.SaveCallback; //導入依賴的package包/類
public SaveCallback getListener() {
return cb;
}
示例2: copyCitysToDB
import org.litepal.crud.callback.SaveCallback; //導入依賴的package包/類
public void copyCitysToDB() {//將所有城市保存到數據庫
boolean cityInited = PreferencesUtil.get(CITY_INITED, false);
if (!cityInited) {
File file = new File(DB_PATH, DB_NAME);
if (file.exists()) {//未初始化卻存在
file.delete();
}
String allcities = FileUtil.assertFile2String("ChinaCityList.json", MyApplication.getContext());
List<County> countyList = JSONHandleUtil.handleCitiesJSONData(allcities);
//對數據進行排序後存入數據庫
Collections.sort(countyList, new CountyComparator());
List<CityDao> cityDaoList = new ArrayList<>();
for (County county : countyList) {
CityDao cityDao = new CityDao();
cityDao.setCityName(county.countyName);
cityDao.setCityId(county.countyNo);
cityDao.setPinyin(county.countyPY);
cityDaoList.add(cityDao);
}
DataSupport.saveAllAsync(cityDaoList).listen(new SaveCallback() {
@Override
public void onFinish(boolean success) {
if (success) {
LogUtil.d("SaveCityDao", "onFinish: " + "Success");
PreferencesUtil.put(CITY_INITED, true);
} else {
LogUtil.d("SaveCityDao", "Failed");
Toast.makeText(MyApplication.getContext(), "城市數據初始化失敗,跳轉至默認城市,\n重啟可重新初始化", Toast.LENGTH_LONG).show();
WeatherActivity.actionStart(MyApplication.getContext(), "CN101280101");
}
}
});
}
}
示例3: listen
import org.litepal.crud.callback.SaveCallback; //導入依賴的package包/類
/**
* Register a callback listener and async task will start executing right away.
* @param callback
* Callback for save records in background.
*/
public void listen(SaveCallback callback) {
cb = callback;
execute();
}