Room Invalidation tracker is initialized twice

本小妞迷上赌 提交于 2019-12-21 09:14:43

问题


I have a horizontal recycler view with custom items in it . Each item can hold the position of current item in the Recycler view . I want to update the item position when item is moved using drag and drop . However the data is getting deleted when there are more then three items in horizontal view.Please Help me out . Source Code

This is what i am getting in Logcat:

E/ROOM: Invalidation tracker is initialized twice :/.

E/Item moved: Counterfrom3

next item:to2

Initialization of database in onCreate.

 db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, DB_NAME)
                .fallbackToDestructiveMigration()
                .allowMainThreadQueries()
                .build();

RecyclerView Adapter code.

@Override
public 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;
}

The code to update the data when items are moved.

 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,
                0, fromContentValues, "posItem =" + fromPosition, null);

        db.getOpenHelper().getWritableDatabase().update(nexName,
                0, toContentValues, "posItem =" + toPosition, null);
        db.setTransactionSuccessful(); //setting Transaction Successful
        } finally {
            db.endTransaction(); // commit or rollback
            db.close(); //closing database
        }
    }

回答1:


When I migrate the database version, same error happens E/ROOM: Invalidation tracker is initialized twice, kills the app, and reopens work. When I started using Room v1.1.0.

But if I keep everything the same and go back to using Room v1.0.0, no such problem occurs and everything works perfectly.

So, May be Room v1.1.0 issue

google issues



来源:https://stackoverflow.com/questions/47691422/room-invalidation-tracker-is-initialized-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!