草庐IT

LiveData_LifecycleBoundObserver_L

全部标签

java - Android LiveData - 如何在不同的 Activity 中重用相同的 ViewModel?

示例View模型:publicclassNameViewModelextendsViewModel{//CreateaLiveDatawithaStringprivateMutableLiveDatamCurrentName;publicMutableLiveDatagetCurrentName(){if(mCurrentName==null){mCurrentName=newMutableLiveData();}returnmCurrentName;}}主要Activity:mModel=ViewModelProviders.of(this).get(NameViewModel.cl

安卓应用移植鸿蒙(四):移植Android的ViewModel和LiveData

经过几天的努力,终于把ViewModel和LiveData移植过来了,代码开源地址:ViewModel_LiveData_for_ohoshttps://gitee.com/ethan-osc_admin/viewmodel_for_ohoshttps://gitee.com/ethan-osc_admin/viewmodel_for_ohos一.基本介绍        ViewModel和LiveData做安卓开发的小伙伴都很熟悉了,我就不过多介绍了,有了他们,我们可以实现MVVM框架,可以让系统自动管理数据的生命周期了,是安卓开发中不可获取的重要组件。笔者在移植网络的库的时候,需要用到这两

android - Room : LiveData from Dao will trigger Observer. onChanged 每次更新,即使 LiveData 值没有变化

我发现,只要DB中的行更新,Dao返回的LiveData就会调用它的观察者,即使LiveData的值显然没有改变。考虑类似以下示例的情况:示例实体@EntitypublicclassUser{publiclongid;publicStringname;//exampleforothervariablespublicDatelastActiveDateTime;}示例道@DaopublicinterfaceUserDao{//Iamonlyinterestedintheusername@Query("SELECTnameFromUser")LiveData>getAllNamesOfUs

android - Room : LiveData from Dao will trigger Observer. onChanged 每次更新,即使 LiveData 值没有变化

我发现,只要DB中的行更新,Dao返回的LiveData就会调用它的观察者,即使LiveData的值显然没有改变。考虑类似以下示例的情况:示例实体@EntitypublicclassUser{publiclongid;publicStringname;//exampleforothervariablespublicDatelastActiveDateTime;}示例道@DaopublicinterfaceUserDao{//Iamonlyinterestedintheusername@Query("SELECTnameFromUser")LiveData>getAllNamesOfUs

android - LiveData 在第一次调用后没有更新它的值

我一直在用头撞墙,我不明白为什么会这样。我正在使用适用于Android的新架构组件,但在使用对象列表更新LiveData时遇到问题。我有两个旋转器。当我更改第一个选项时,第二个必须更改其内容。但是最后一部分没有发生。谁能帮帮我?State.java@Entity(tableName="states")publicclassState{@PrimaryKey(autoGenerate=false)privateintid;privateStringname;@ColumnInfo(name="countryId")privateStringCountryId;@Ignoreprivate

android - LiveData 在第一次调用后没有更新它的值

我一直在用头撞墙,我不明白为什么会这样。我正在使用适用于Android的新架构组件,但在使用对象列表更新LiveData时遇到问题。我有两个旋转器。当我更改第一个选项时,第二个必须更改其内容。但是最后一部分没有发生。谁能帮帮我?State.java@Entity(tableName="states")publicclassState{@PrimaryKey(autoGenerate=false)privateintid;privateStringname;@ColumnInfo(name="countryId")privateStringCountryId;@Ignoreprivate

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(