其他分享
首页 > 其他分享> > Android(JetPack)学习(12)Room2

Android(JetPack)学习(12)Room2

作者:互联网

Room2

在这里插入图片描述
viewmodel向后一步,设立仓库Repository

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

static class InsertTask extends AsyncTask<Word,Void,Void>{

        private WordDao wordDao;

        public InsertTask(WordDao wordDao) {
            this.wordDao = wordDao;
        }

        @Override
        protected Void doInBackground(Word... words) {
            wordDao.insertW(words);
            return null;
        }
    }

    static class UpdateTask extends AsyncTask<Word,Void,Void>{

        private WordDao wordDao;

        public UpdateTask(WordDao wordDao) {
            this.wordDao = wordDao;
        }

        @Override
        protected Void doInBackground(Word... words) {
            wordDao.updateW(words);
            return null;
        }
    }
    static class DeleteTask extends AsyncTask<Word,Void,Void> {

        private WordDao wordDao;

        public DeleteTask(WordDao wordDao) {
            this.wordDao = wordDao;
        }

        @Override
        protected Void doInBackground(Word... words) {
            wordDao.deleteW(words);
            return null;
        }
    }

    static class DeleteAllTask extends AsyncTask<Void,Void,Void> {

        private WordDao wordDao;

        public DeleteAllTask(WordDao wordDao) {
            this.wordDao = wordDao;
        }

        @Override
        protected Void doInBackground(Void...Void) {
            wordDao.deleteALLW();
            return null;
        }
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

标签:12,JetPack,Void,private,WordDao,AsyncTask,words,Android,wordDao
来源: https://blog.csdn.net/qq_43352282/article/details/104746931