I have been using the samples for creating some small apps. I have been working on GithubBrowserSample, maintaining the same architecture implementation as closely as possible.
When the app goes into the background, 60% of the times it crashes with an error saying :
10-16 12:37:46.817 30218-30261/com.yatra.corpbase A/sp: sp<> assignment detected data race
10-16 12:37:46.822 30218-30261/com.yatra.corpbase A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 30261 (RenderThread)
I came to understand that this happens when we do some long-running tasks on UI thread. I am fairly certain this is caused by some leak from LiveData/ViewModel, as this is happening in very small projects built on the same architecture.
I have been trying to resolve this for days. So any help would be appreciated.
Depends on what you are doing on the main thread. Did you try checking the anr file?
By design, live data observers run on the UI thread but the samples never do any long running operation on the UI thread (unless there is a bug in the sample app).
If you can share the anr file, maybe it can explain what is going on. Of course, it might also be in some code you've added so anr is necessary to get to the actual problem.
@yigit For more information, this only happens as soon as the app goes into background. And I am very sure I am not doing anything (not even overriding) in any onPause()/onStop() method.
I understand that this description is too broad and I appreciate you taking time to reply. I will provide more crash logs if possible, although the logcat doesn't show anything but the lines I mentioned.
I write this down maybe somebody has the same problem. I don't know what happened in your case, but for me I was using a drawable animation like this:
poiAnimation = ic_poi_animation.drawable as AnimatedVectorDrawable
poiAnimation?.registerAnimationCallback(
object: Animatable2.AnimationCallback() {
override fun onAnimationEnd(drawable: Drawable?) {
poiAnimation?.start()
}
})
poiAnimation?.start()
So everytime the animation finished it started itself again and for a long loading time it was called 30 times, but my poiAnimation?.stop() was called only once. If you stop the animation exactly the same amount of times that you started it, it will work.
This doesn't seem to be an issue with the samples here. If you do track this down to something related to Lifecycle, please file a bug against Lifecycle.
Most helpful comment
I write this down maybe somebody has the same problem. I don't know what happened in your case, but for me I was using a drawable animation like this:
poiAnimation = ic_poi_animation.drawable as AnimatedVectorDrawable poiAnimation?.registerAnimationCallback( object: Animatable2.AnimationCallback() { override fun onAnimationEnd(drawable: Drawable?) { poiAnimation?.start() } }) poiAnimation?.start()So everytime the animation finished it started itself again and for a long loading time it was called 30 times, but my
poiAnimation?.stop()was called only once. If you stop the animation exactly the same amount of times that you started it, it will work.