Bug P3
Status Update
Comments
ro...@gmail.com <ro...@gmail.com> #2
Forgot to note the environment.
This crash occurs on only API 21.
This crash occurs on only API 21.
ro...@gmail.com <ro...@gmail.com> #3
This crash occurs on API 22 and 23 when the user doesn't have Google Play installed. Related discussions: https://stackoverflow.com/q/41025200/842697
Description
AI-183.4284.148.34.5159543, JRE 1.8.0_152-release-1248-b01x64 JetBrains s.r.o, OS Windows 10(amd64) v10.0 , screens 1600x900, 1920x1080
Android Gradle Plugin: 3.4.0-alpha07
Gradle: 5.0
NDK: from local.properties: (not specified); latest from SDK: (not found);
LLDB: pinned revision 3.1 not found; latest from SDK: (package not found);
CMake: from local.properties: (not specified); latest from SDK: (not found); from PATH: (not found);
IMPORTANT: Please read
---
In one of my projects I have found an issue where the sequence:
MediatorLiveData.removeSource(LiveData)
"aguire new LiveData"
MediatorLiveData.addSource(LiveData)
does not work as expected
the first source seems to be added along with the last added source even if removesource is called upon the first.
Below is an example (in kotlin) where this source shift is done
when logging my data, livedata is triggered from the original source even I know I have removed it. It does not seem to trigger between remove and the add though.
--
liveStation is a LiveData<List<StationWithKindPrice>> where StationWithKindPrice is an entity
getLiveStationsWithKindPrice() and getLiveStationsWithKindPriceUser() returns both
LiveData<List<StationWithKindPrice>> but uses different queries from a Room Dao.
Simple logic below to do the change:
fun setSource(kindId: String)
{
Log.i(TAG,"setSource = "+kindId)
if((kindId==null)||(kindId == "0")||(kindId == ""))
{
if(currentSource != "0")
{
Log.i(TAG,"source changed to anonymous")
mediatorLiveStations.removeSource(liveStations)
liveStations = stationListRepository.getLiveStationsWithKindPrice()
mediatorLiveStations.addSource(liveStations, mediatorLiveStations::setValue)
currentSource = "0"
}
}
else
{
if((currentSource == "0")||(currentSource == "")) {
Log.i(TAG,"source changed to user ")
mediatorLiveStations.removeSource(liveStations)
liveStations = stationListRepository.getLiveStationsWithKindPriceUser("user")
mediatorLiveStations.addSource(liveStations, mediatorLiveStations::setValue)
currentSource=kindId
}
}
}
Is there an issue when using the same variable (var) to both remove the source, reaquire new variable containing the same datastructure (but different source) and reintroducing it will introduce the old source also ?
I can surely see that both sources are called after I have done a "change" as shown above, there should only be one. Both are called, and its arbitrary which comes first. The second call overwrites the data in the first call.
12-12 09:13:16.074 28920-28920/no.rogo.projectfk303 I/StationListFragment: viewMode.getStations().observing stations [] <--- Expected, from the one that was added
12-12 09:13:16.104 28920-28920/no.rogo.projectfk303 I/StationListFragment: viewMode.getStations().observing stations [StationWithKindPrice(stationId=567, stationName=Gas Tech Stryn, longitude=6.703216, latitude=61.903396, airDistance=2.02335302734375, imageUrl=
I will try to work out an simple proof-of-concept project shortly.
I have seen similar issues earlier talking about an reentry or reenter issue according to removeSource and addSource, couldn't find it, but that one should have been fixed then.
RG