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 8049431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:47:00+00:00 2026-06-05T06:47:00+00:00

This is not a question about Context object itself. I wonder what the best

  • 0

This is not a question about Context object itself. I wonder what the best way to manage reference to it. When I create android objects like Activity, Service, etc – context already accessible everywhere.

But I have bunch of different classes for data access, various shared utilities, etc. I find myself writing every call and passing context alone. I wonder if there any good way to deal with context. Maybe static? Is that good idea to store reference in my own Application object like so?

public class MyApplication extends Application
{
    public static Context Context;

This way I can access context from anywhere in application. Does it seem like a good idea?

  • 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-06-05T06:47:01+00:00Added an answer on June 5, 2026 at 6:47 am

    Make public static Context mContext; as a global variable, and at the start of onCreate(), add mContext = this;. It makes access much easier. By making it public and static, other files can see the context of your main activity, and you won’t have to pass it as a parameter to any function. In my opinion, this is probably the best/easiest way to manage reference to it. It also unclutters all sorts of references to MainActivity.this.

    alextsc’s comment shows a helpful link to problems that can occur from this as well.

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

Sidebar

Related Questions

This question is not about which is the best, it is about which makes
This question is not about 'best' barcode library recommendation, we use various products on
This is a newbie question. What is the best way to pass an object
This is not a question about a specific framework. I am using plain php
This is not a question about jQuery, but about how jQuery implements such a
Disclaimer: this is not a question about how to install asp.net or an application
Please note this is not a question about online/hosted SVN services. I am working
(note that this question is not about CAS, it's about the May fail spuriously
Please note: This is a question about the Eclipse plugin Subversive , and not
Sorry this is not a very well defined question, I am thinking about an

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.