Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

@EBean Singleton doesnt compile #197

Closed

Description

@pleerock

In the https://github.com/excilys/androidannotations/wiki/Enhance%20custom%20classes tutorial next code gives me an error: "Singleton cannot be resolved to a variable"

@EBean(scope = Singleton)

I tried to replace it to

@EBean(scope = Scope.Singleton)

and it compiles but my ebean doesnt work (views arent loading, listeners arent working)

Activity

  1. pyricau commented on May 19, 2012

    @pyricau
    Contributor

    Hi @pleerock,

    Thank you for pointing out this error in the documentation. That's because we usually do a static import on Scope.Singleton. I updated the documentation in that respect.

    Regarding your other problem, it's related to the singleton scope, as stated in the documentation :

    If your bean has a Singleton scope, it will only keep a reference to the application context (using context.getApplicationContext(). That's because it leaves longer then any activity / service, so it shouldn't keep a reference to any such Android component, to avoid leaks.

    We also skip view injection in that case, because views usually contain references to the activity, so that would also lead to a memory leak. This problem was also pointed out in #186.

    What do you need a singleton for? What's your use case?

    If I answered your questions, please do not hesitate to close the issue :) .

  2. pyricau commented on May 19, 2012

    @pyricau
    Contributor

    I updated the documentation with more details:

    • We also disable view injection and view event binding in @EBean components with Singleton scope, for the exact same reason (views have a reference to the activity, which may therefore create a leak).
  3. pleerock commented on May 19, 2012

    @pleerock
    Author

    Each of my activity has its own ActivityNameViewHolder for holding all view components of an activity. So I want to set this ActivityNameViewHolder as singleton to access it from different classes without recreating it or holding somewhere else

  4. pyricau commented on May 20, 2012

    @pyricau
    Contributor

    I see :) . The singleton pattern is for components that live as long as the app live. This doesn't fit your use case. What you actually need is an Activity scope. We don't provide that for now, but we probably should :) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions