当我在模拟器上运行应用程序时它工作正常但它立即在我的手机上打开和关闭并得到这个
W/Looper: Slow Looper main: Long Msg: seq=7 plan=13:35:52.606 late=267ms wall=1940ms running=0ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver
I/Choreographer: Skipped 220 frames! The application may be doing too much work on its main thread.
W/Looper: Slow Looper main: doFrame is 1834ms late because of 4 msg, msg 1 took 1940ms (seq=7 late=267ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver), msg 4 took 81ms (seq=10 late=1757ms h=android.os.Handler c=androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1)
I/Process: Sending signal. PID: 28010 SIG: 9
它工作正常,我不知道发生了什么,但我确定房间里的问题
到
@Dao
interface WordDao {
@Query("SELECT * FROM vocabulary_table ORDER BY last_revision ASC")
fun get(): Flow<List<Vocabulary>>
}
存储库
class VocabularyRepository(private val wordDao: WordDao) {
val allVocabulary = wordDao.get()
}
视图模型
class HomeViewModel(application: Application):AndroidViewModel(application) {
private val vocabularyRepository = getApplication<WordApplication>().vocabularyRepository
val allVocabulary = vocabularyRepository.allVocabulary
}
撰写功能
@Composable
fun HomeScreen(
onNavigateToForm:() -> Unit,
onNavigateToReview:() -> Unit,
onNavigateToSettings:() -> Unit,
onNavigateToRecall:(id:Long) -> Unit
){
val homeViewModel:HomeViewModel = viewModel()
val allVocabulary = homeViewModel.allVocabulary.collectAsState(initial = emptyList())
Text(allVocabulary.value.size.toString())
}