Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:39:48+00:00 2026-05-24T22:39:48+00:00

I just started using Roboguice (+Guice) and I am not sure about the best

  • 0

I just started using Roboguice (+Guice) and I am not sure about the best practice how to use it.

In my Activity I have about 5 functions (out of about 30) which uses an object called “ProviderQueries” (Singleton). I could use it in two ways:

1.)

    protected void onResume() {
       super.onResume();
       getInjector().getInstance(ProviderQueries.class).setLanguage("EN");
}

2.)

class MyActivity extends RoboActivity {
    @Inject
    private ProviderQueries pv;

    ...

       protected void onResume() {
          super.onResume();
          pv.setLanguage("EN");
          }        
 }

1 – too long but the instance of ProviderQueries is used where it is needed

2 – short and nice but “pv” is available for the whole Activity but only needed in 5 different function…

Which approach would you use, or do you have a better solution?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:39:49+00:00Added an answer on May 24, 2026 at 10:39 pm

    This is a bit of a judgement call. To me, 5 functions seems justification enough to put this in a member variable, which uses a cleaner syntax and reduces the explicit dependency on the injector. I see your point about it not being used in all 30 methods, but that seems of a secondary concern in my personal opinion (your own sense of aesthetics of course may be different).

    If ProviderQueries is especially memory intensive, you may want to consider going with option 2 instead of 1 since option 1 will keep the object live for the duration of the activity. Not a consideration for most objects, but could be an issue for some.

    If you weren’t using Guice, how would you access your singleton? Presumably through an accessor method? You can, of course, always write your own accessor that performs #2 for you in a more compact way, although it won’t bypass the small reflection overhead incurred for each access to the singleton.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started using Rails and am not sure what I'm not doing correctly.
I just started using events and delegates in C# and I'm not sure if
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I just started using SVN, and I have a cache directory that I don't
just started using log4j in one of my home-projects and I was just about
I just started using Matlab, and I absolutely despise (or not properly understand), the
Just started using Blueprint CSS and now playing with the grids but have a
I´ve just started using ASIHTTPRequest for iOs and I have a small issue with
I just started using Log4Net and was looking to see what you have found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.