android – Room Invalidation tracker初始化两次

android – Room Invalidation tracker初始化两次,第1张

概述我有一个水平回收站视图,其中包含自定义项目.每个项目都可以在Recycler视图中保存当前项目的位置.我想使用拖放移动项目时更新项目位置.但是当水平视图中有三个以上的项目时,数据会被删除.请帮帮我. Source Code 这是我在Logcat中得到的: E/ROOM: Invalidation tracker is initialized twice :/. E/Item moved: Coun 我有一个水平回收站视图,其中包含自定义项目.每个项目都可以在Recycler视图中保存当前项目的位置.我想使用拖放移动项目时更新项目位置.但是当水平视图中有三个以上的项目时,数据会被删除.请帮帮我.
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初始化两次所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1138650.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存