jjzjj

LiveData

全部标签

java - LiveData vs Handler 和 LocalBroadcast

我有旧的Android/java代码,其中包含两个派生自IntentService,并且这些服务不在单独的进程中运行。问题是关于从这些IntentService返回结果的方式。一个服务返回结果,使用Handler+Runnable,在主循环中运行代码:newHandler(Looper.getMainLooper()).post(newRunnable(){@Overridepublicvoidrun(){MyApplication.get().setFoo(someThing);}});另一种是使用LocalBroadcastManager.getInstance(this).sen

java - LiveData vs Handler 和 LocalBroadcast

我有旧的Android/java代码,其中包含两个派生自IntentService,并且这些服务不在单独的进程中运行。问题是关于从这些IntentService返回结果的方式。一个服务返回结果,使用Handler+Runnable,在主循环中运行代码:newHandler(Looper.getMainLooper()).post(newRunnable(){@Overridepublicvoidrun(){MyApplication.get().setFoo(someThing);}});另一种是使用LocalBroadcastManager.getInstance(this).sen

安卓机房 : LiveData callback of update insert?

我有一个SimpleDAO包括CRUD功能FeedEntryDAO.java@DaopublicinterfaceFeedEntryDAO{@Query("SELECT*FROMfeedEntrys")LiveData>getAll();@Query("SELECT*FROMfeedEntrysWHEREuid=:uidLIMIT1")LiveDatafindByUid(intuid);@InsertvoidinsertAll(FeedEntry...feedEntries);@Deletevoiddelete(FeedEntryfeedEntry);@Updateintupdate(

安卓机房 : LiveData callback of update insert?

我有一个SimpleDAO包括CRUD功能FeedEntryDAO.java@DaopublicinterfaceFeedEntryDAO{@Query("SELECT*FROMfeedEntrys")LiveData>getAll();@Query("SELECT*FROMfeedEntrysWHEREuid=:uidLIMIT1")LiveDatafindByUid(intuid);@InsertvoidinsertAll(FeedEntry...feedEntries);@Deletevoiddelete(FeedEntryfeedEntry);@Updateintupdate(

android - 具有多个参数的 MediatorLiveData 或 switchMap 转换

我正在使用Transformations.switchMap在我的ViewModel中,所以在我的fragment中观察到的LiveData集合会对code参数的更改使用react。这很好用:publicclassMyViewModelextendsAndroidViewModel{privatefinalLiveDatadayPrices;privatefinalMutableLiveDatacode=newMutableLiveData();//privatefinalMutableLiveDatanbDays=newMutableLiveData();privatefinalDB

android - 具有多个参数的 MediatorLiveData 或 switchMap 转换

我正在使用Transformations.switchMap在我的ViewModel中,所以在我的fragment中观察到的LiveData集合会对code参数的更改使用react。这很好用:publicclassMyViewModelextendsAndroidViewModel{privatefinalLiveDatadayPrices;privatefinalMutableLiveDatacode=newMutableLiveData();//privatefinalMutableLiveDatanbDays=newMutableLiveData();privatefinalDB

android - LiveData.getValue() 使用 Room 返回 null

JavaPOJO对象publicclassSection{@ColumnInfo(name="section_id")publicintmSectionId;@ColumnInfo(name="section_name")publicStringmSectionName;publicintgetSectionId(){returnmSectionId;}publicvoidsetSectionId(intmSectionId){this.mSectionId=mSectionId;}publicStringgetSectionName(){returnmSectionName;}pub

android - LiveData.getValue() 使用 Room 返回 null

JavaPOJO对象publicclassSection{@ColumnInfo(name="section_id")publicintmSectionId;@ColumnInfo(name="section_name")publicStringmSectionName;publicintgetSectionId(){returnmSectionId;}publicvoidsetSectionId(intmSectionId){this.mSectionId=mSectionId;}publicStringgetSectionName(){returnmSectionName;}pub

android - LiveData 在第一次回调后删除观察者

收到第一个结果后如何移除观察者?以下是我尝试过的两种代码方式,但即使我删除了观察者,它们都会继续接收更新。Observerobserver=newObserver(){@OverridepublicvoidonChanged(@NullableDownloadItemdownloadItem){if(downloadItem!=null){DownloadManager.this.downloadManagerListener.onDownloadManagerFailed(null,"thisitemalreadyexists");return;}startDownload();mo

android - LiveData 在第一次回调后删除观察者

收到第一个结果后如何移除观察者?以下是我尝试过的两种代码方式,但即使我删除了观察者,它们都会继续接收更新。Observerobserver=newObserver(){@OverridepublicvoidonChanged(@NullableDownloadItemdownloadItem){if(downloadItem!=null){DownloadManager.this.downloadManagerListener.onDownloadManagerFailed(null,"thisitemalreadyexists");return;}startDownload();mo