Skip to content

Event observers in singleton are registered multiple times #157

@goodsoft

Description

@goodsoft

Consider the following situation:

@Application
class App {
    @Inject Library lib;
}
@Activity
class Main {
    @Inject Library lib;
}
@Singleton
class Library {
    @Observes
    void onEvent (SomeEvent event) {
        // handle event
    }
}

In this situation event observer is registered and executed twice.
And each injection in each component registers yet another observer.

I've looked through generated code and I think the best way to solve this problem is to register observers for singletons not in component's onCreate method, but in singleton's ...$$UnscopedProvider.get method.
This would also solve the problem of observers' persistence between different activities, services etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions