Is there a way to use Android's LifecycleObserver to notify about onActivityResult?
H

1

6

I currently use LifecycleObserver for notifying about events such as onStart of my view. This is great for components as presenters or handlers, such as FacebookLoginHandler that needs to register the callback once the view is ready. However, there are some situations, as the one I've mention, that I wanted my handler to handle the returned data of another activity.

Example:

When I choose to login with Facebook, it starts another activity and the return of it goes to view's onActivityResult method. this makes me inject my FacebookLoginHandler in the view, only to delegate the handling back to it. I wanted to use LifecycleObserver to get notified of onActivityResult and avoid having to couple my handler to the view only for delegating this event. Is there a way to do that?

Hardej answered 6/1, 2018 at 10:27 Comment(0)
S
4

I had exactly the same problem. I have "sign in with Facebook" functionality in my app and I want to move this functionality into separate class AuthManager that implements LifecycleObserver.

I have checked Lifecycle.Event class that contains all the available lifecycle events. Looks like at the moment (android.arch version 1.1.0) there is no event for hading onActivityResult() with LifecycleObserver.

Opened an issue about this: https://github.com/googlesamples/android-architecture-components/issues/317

Sussi answered 2/3, 2018 at 17:19 Comment(3)
have you find solution to this ?Bentz
The issue was closed since it was opened on the samples project. I opened one in the issue tracker: issuetracker.google.com/issues/140476665Colander
have you find solution to this? (After 2 years)Favors

© 2022 - 2024 — McMap. All rights reserved.