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

  • Home
  • SEARCH
  • 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 1043969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:45:09+00:00 2026-05-16T15:45:09+00:00

It annoys me when I need to pass the context reference around all over

  • 0

It annoys me when I need to pass the context reference around all over my code. So I am thinking to create a static method to return a reference to the application instance. I am not sure if it is safe to assume there is only one instance of the Application in one application. Apparently, the Application class in Android SDK doesn’t provide such method to return the instance reference. So I suspect there must be a reason?

  • 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-16T15:45:10+00:00Added an answer on May 16, 2026 at 3:45 pm

    It’s probably safe, assuming that your android app lives within a single os process (most do, but this isn’t a guarantee on android), but I advise against it.

    If you need access to the context/application outside of the places where it’s already available (activities, services, broadcast receivers, applications, views, etc), you’re probably letting details related to the android environment creep into code that shouldn’t know so much about it.

    The big exception is static utility methods (e.g. to display a canned dialog that you reuse in your app or similar), in which case passing your context is kind of a convention in the android world (for example, ProgressDialog.show takes a Context as its first argument).

    While you can do this, my feeling is that it’s probably a band-aid to work around the fact that you have too many components in your code that are unnecessarily tightly coupled to the android environment.

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

Sidebar

Related Questions

If you create a new MFC application (with MFC Feature Pack), and using all
Code that is untestable really annoys me. The following things make oo-code untestable: global
I did my first Silverlight 2 application and what annoys be is that text-fonts
I need to pass along a string with my FileReference, or provide that string
Here is a sample of code that annoys me: class Base { protected: virtual
One thing that annoys me when debugging programs in Visual Studio (2005 in my
One thing really really annoys me about the Eclipse ide : its find UI
I need to parse a string like func1(arg1, arg2); func2(arg3, arg4); . It's not
This behavior annoys me quite a lot. I specified '....\bin\Debug\' as output folder for
I've got a collection of strings, and I need to know the first index

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.