Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.x: fix lifecycle if pass lifecycleOwner (Activity, Fragment) to Scarlet.… #71

Open
wants to merge 9 commits into
base: 0.2.x
Choose a base branch
from
Open

Conversation

hantrungkien
Copy link

@hantrungkien hantrungkien commented Apr 12, 2019

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.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

@aaulia
Copy link

aaulia commented Jul 30, 2019

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).

@hantrungkien
Copy link
Author

@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

@aaulia
Copy link

aaulia commented Jul 30, 2019

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.

@hantrungkien
Copy link
Author

@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

@aaronweihe
Copy link
Collaborator

aaronweihe commented Jul 30, 2019

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.

@aaronweihe aaronweihe changed the title fix lifecycle if pass lifecycleOwner (Activity, Fragment) to Scarlet.… 0.2.x: fix lifecycle if pass lifecycleOwner (Activity, Fragment) to Scarlet.… Jul 30, 2019
@aaulia
Copy link

aaulia commented Jul 31, 2019

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.

@Abdelrhmanwalid
Copy link

Abdelrhmanwalid commented Sep 29, 2019

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?

@vrjgamer
Copy link

vrjgamer commented Jul 7, 2020

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.

@hantrungkien
Copy link
Author

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?

@vrjgamer
Copy link

I haven't, let me check that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants