Scarlet
Scarlet copied to clipboard
0.2.x: fix lifecycle if pass lifecycleOwner (Activity, Fragment) to Scarlet.…
If we setup Scarlet with lifecycleOwner from Activity or Fragment then when onDestroy them Lifecycle's Scarlet will still retry again.
val configuration = Scarlet.Configuration(
lifecycle = AndroidLifecycle.ofLifecycleOwnerForeground(application, **this**),
messageAdapterFactories = listOf(ProtobufMessageAdapter.Factory(registry)),
streamAdapterFactories = listOf(RxJava2StreamAdapterFactory())
)
After debug I found this issue by the extension function List<LifecycleState>.combine(). In this only check and return Started or Stopped. If in list contains any state = Completed, it must have return Completed to Scarlet know observeWebSocketEvent which registed was completed.
fun List<LifecycleState>.combine(): LifecycleState {
val shouldStop = any { it == LifecycleState.Stopped }
val completed = any { it == LifecycleState.Completed }
return when {
shouldStop -> LifecycleState.Stopped
completed -> LifecycleState.Completed
else -> LifecycleState.Started
}
}
unregister connectivity broadcast receiver when lifecycleState = Completed in FlowableLifecycle
Any news in merging this? I also have this issue and have look at the code, it indeed only output Started and Stopped but not Completed (or should I say, Completed fall through as Started).
@aaulia Now that I have more experience in working with WebSocket via Tider Scarlet, I think this PR isn't necessary. But if you have one special case which have to use and you think this PR will born for your issue, you will get it in here https://github.com/hantrungkien/tinder-scarlet-lifecycle-android
Now that I have more experience in working with WebSocket via Tider Scarlet, I think this PR isn't necessary.
@hantrungkien could you elaborate? Am I using Scarlet wrong?
My use case is to tie the Scarlet Lilfecycle to an Activity Lifecycle, so when the Activity is started it would open a connection and when the Activity destroyed, Scarlet would close and shutdown. But what happen now is, when the Activity is destroyed, Scarlet will close, and then immediately re-open, the connection.
@aaulia Please think of using as Retrofit. It should be use like as single instance. When run app, you should create it and then when you entered in Activity just change state of AuthStatus to true and vice versa when you exited. If LifecycleState of Scarlet change to Complete, you will have to recreate Scarlet instance.
https://github.com/Tinder/Scarlet/blob/0.2.x/demo/src/main/java/com/tinder/app/websocket/echo/domain/AuthStatus.kt
thanks for the contribution! the lifecycle owner module is an example to show how android lifecycle would be intergraded. but i'm open to suggestions to make it extensible.
thanks for the contribution! the lifecycle owner module is an example to show how android lifecycle would be intergraded. but i'm open to suggestions to make it extensible.
Making some of the class public instead of internal would be nice. For example the ConnectivityOnLifecycle.
My use case is to tie the Scarlet Lilfecycle to an Activity Lifecycle, so when the Activity is started it would open a connection and when the Activity destroyed, Scarlet would close and shutdown. But what happen now is, when the Activity is destroyed, Scarlet will close, and then immediately re-open, the connection.
We're facing the same issue in both 0.1.9 & 0.2.5, any idea if we're doing something wrong or how to fix it?
is the scarlet-lifecycle-android module not included in the 0.1.9 version of the library. I am not able to find AndroidLifecycle class in this build.
is the scarlet-lifecycle-android module not included in the 0.1.9 version of the library. I am not able to find AndroidLifecycle class in this build.
@vrjgamer have you tried 0.2.4 branch?
I haven't, let me check that out.