![]()
Source Code
这是我在Logcat中得到的:
E/ROOM: InvalIDation tracker is initialized twice :/.
E/Itemmoved: Counterfrom3
next item:to2
在onCreate中初始化数据库.
db = Room.databaseBuilder(getApplicationContext(),AppDatabase.class,DB_name) .fallbackToDestructiveMigration() .allowMainThreadQuerIEs() .build();
RecyclerVIEw适配器代码.
@OverrIDepublic boolean onItemmove(int fromposition,int toposition) { String name = dataSet.get(fromposition).getname(); //this will make "Add item" do not move from its first position.. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (!(Objects.equals(name,"Add") || (toposition == 0 && fromposition == 1))) { Collections.swap(dataSet,fromposition,toposition); MoveItem(fromposition,toposition); notifyItemmoved(fromposition,toposition); return true; } } return false;} 移动项目时更新数据的代码.
public static voID MoveItem(int fromposition,int toposition){ String name = data.get(fromposition).getname(); //This gets the current item name in the vIEw String nexname = data.get(toposition).getname(); //This gets the next item name in the vIEw ContentValues fromContentValues = new ContentValues(); fromContentValues.put("posItem",toposition); //adding data to ContentValues ContentValues toContentValues = new ContentValues(); toContentValues.put("posItem",fromposition); Log.e("Item moved",name + "from" + fromposition + "\n" + "next item:" + "to" + toposition); db.beginTransaction(); try { db.getopenHelper().getWritableDatabase().update(name,fromContentValues,"posItem =" + fromposition,null); db.getopenHelper().getWritableDatabase().update(nexname,toContentValues,"posItem =" + toposition,null); db.setTransactionSuccessful(); //setting Transaction Successful } finally { db.endTransaction(); // commit or rollback db.close(); //closing database } }解决方法 当我迁移数据库版本时,同样的错误E / ROOM:失效跟踪器被初始化两次,并杀死应用程序,并重新打开工作.当我开始使用Room v1.1.0时. 但是,如果我保持一切相同并回到使用Room v1.0.0,那么就不会出现这样的问题,一切都很完美.
所以,可能是Room v1.1.0问题
google issues
总结以上是内存溢出为你收集整理的android – Room Invalidation tracker初始化两次全部内容,希望文章能够帮你解决android – Room Invalidation tracker初始化两次所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)