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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:22:03+00:00 2026-06-12T09:22:03+00:00

Need to access resources from non-context class without passing context through deep call stack.

  • 0

Need to access resources from non-context class without passing context through deep call stack.

I’ve already read all answers on this topic, but this class is not created from Activity, and it’s really far from it. The way to send context through all calls is not a variant, because it’ll require to send it through a number of classes and methods which does not any need to know something about context.

Do I have any chance to access resources without passing context through a really deep call stack? Any static methods needed? It would be really amazing if it’s impossible to get application resources from any place of application with an easy and natural way.

  • 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-12T09:22:04+00:00Added an answer on June 12, 2026 at 9:22 am

    You can extends Android’s Application class and implement it as a singleton which will make it globally available.

    public class SampleApplication extends Application {
        private static SampleApplication INSTANCE;
    
        @Override
        public void onCreate() {
            super.onCreate();
            INSTANCE = this;
        }
    
        public static SampleApplication instance() {
            return INSTANCE;
        }
    }
    

    If you do this it requires some work in the AndroidManifest.xml. This will tell the framework to load your Application instead of the default application.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.yourdomain"
      android:versionCode="1"
      android:versionName="1.0">
    
    <application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name"
        android:name=".SampleApplication">
        <activity android:name=".SampleActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

    This will easily give you a mechanism to grab your Application context whenever necessary. You can even implement a static method that returns your resources, but the following should work.

    SampleApplication.instance().getResources();
    

    Don’t know if you have tried this, but it should work. I didn’t test this code, so it may take some tweaking, but you should get the idea.

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

Sidebar

Related Questions

I need to access the resource files in my web project from a class.
I need access to the uint64_t typedef from stdint.h in some wrapper code that
I know that's bad design, but I need access to the view from my
I need to access a components tag attribute like: <h:inputtext id=input_age/> from a backing
I need to access the commandline from within a C# application. I can't find
I need to access camera from a remote html page. I load this html
I need to access multiple models from a single view. Previously, my links_controller was
I need to fetch data from a URL with non-ascii characters but urllib2.urlopen refuses
I need load external resources from another server like css, template, data... but I
I have an application which need to access context in a lot of different

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.