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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:56:28+00:00 2026-06-15T01:56:28+00:00

I have some static xml data that I want to read once and store

  • 0

I have some static xml data that I want to read once and store globally. Initially I simply read the file from an activity into a Map, however, I now need to access the data from multiple activities so I want to avoid reading it from the file from each activity.

I’m using XmlPullParser which requires a context. My problem is that I want to store it into a static variable like so…

public static Map<String,String> myXmlData=getXmlData(???);

but I don’t know how to get the application context in a static way.

public static Map<String, String> getXMLData(Context ctx){
    Map<String, String> data = new HashMap<String, String>();
    XmlPullParser parser = ctx.getResources().getXml(R.xml.mydata );
    ...

}

I tried removing the ctx parameter, from the static method above, and calling GetApplicationContext() but the compiler didn’t like that I was trying to make that call from a static method.

Any ideas anyone?

  • 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-15T01:56:29+00:00Added an answer on June 15, 2026 at 1:56 am

    You should extend the Application class on your app. This is the entry point for app-wide resources that need to be initialized.

    Application.onCreate will be one of the first things of your application to be executed when the user launches your app.

    Since Application extends context, you can get anything you might need to initialize your app ( resources, refereces, system services, etc ).

    Here’s a tutorial http://www.helloandroid.com/tutorials/maintaining-global-application-state

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

Sidebar

Related Questions

I want to add one xml file (which has some static data related to
I have some reference data in a text file (~5MB) that I want to
I have a file which is an XML representation of some data that is
I have some classes that already use DOM4J to read XML files and provide
I have a script that loads info from external XML file and inserts it
I have a static method that validates some XML. In order to validate the
I have some static resources (images and HTML files) that will be localized. One
I have some static text that needs to show up at 2 locations within
I have some code that looks like: static const std::string and( AND ); This
Suppose I have a XML schema and want to support some extensions at several

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.