Android ORMLite slow create object

前端 未结 1 1721
情深已故
情深已故 2021-01-13 12:38

I am using ormLite to store data on device. I can not understand why but when I store about 100 objects some of them stores too long time, up to second. Here is the code

1条回答
  •  迷失自我
    2021-01-13 12:55

    Thanks to Gray! Solution is, as mentioned Gray, using callBatchTasks method:

    public void updateListOfObjects (final List  list) {
        try {
            getHelper().getObjectDao().callBatchTasks(new Callable (){
            @Override
            public Object call() throws Exception {
                for (Object obj : list){
                    getHelper().getObjectDao().createOrUpdate(obj);
                    }
                return null;
            }
    
        });
    } catch (Exception e) {
        Log.d(TAG, "updateListOfObjects. Exception " + e.toString());
    }
    }
    
    
    

    Using this way, my objects (two types of objects, 1st type - about 100 items, 2nd type - about 150 items) store in 1.7 sec.

    See the ORMLite documentation.

    0 讨论(0)
    提交回复
    热议问题