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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:18:10+00:00 2026-05-27T04:18:10+00:00

I need to find a solution that holds and accesses large chunks of complex

  • 0

I need to find a solution that holds and accesses large chunks of complex global data and methods. It has to be accessible from within activities and normal instance variables of various data classes.

This is how I have done it. I would just like to know if there is anything wrong with it or if there is a better/cleaner way.

First I extend Application like recommended many times…

public class MainDataManager extends Application{

   public ... large chunks of data in arrays, lists, sets,....

   //static variable for singleton access from within instance variables of other classes
   public static MainDataManager mainDataManager;

  //create and init the global data, and store it in the static variable of the class
  @Override
      public void onCreate() {
        super.onCreate();
        //in case it should get called more than once for any reason
        if (mainDataManager == null) {
            init();
            mainDataManager = this;
            }
      }

Now accessing it from within activities like everywhere recommended…

MainDataManager mainDataManager = (MainDataManager)getApplicationContext();

And since I need to access it from normal instances of data classes …

public class MyDataClass {
    public MainDataManager mainDataManager;
    public String name;

    public MyDataClass(String namex) {
        this.name = namex;
        //this is why I defined the static variable within MainDataManager, so
        //one has access to it from within the instance of MyDataClass
        this.mainDataManager = MainDataManager.mainDataManager;
    }

      public void examplesForAccessing() {
      //some examples on how to access the global data structure and associated methods
        mainDataManager.someMethodAccess();
        xyz = mainDataManager.someDataAccess;
        mainDataManager.someIndirectMethodAccess.clear();
        mainDataManager.someOtherData = false;
    }
}

Since I have not done this so far, I would like to know if there is anything wrong with this. Memory, efficiency, …

Thanks very much!

May I add a little sidenote?
I could also have just used a class MainDataClass and access by MainDataClass.var or MainDataClass.method(). Is there any REAL disadvantage?

Is the data in both cases held in heap/stack?

  • 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-27T04:18:10+00:00Added an answer on May 27, 2026 at 4:18 am

    You haven’t given much detail about your “large chunks of data” but keep in mind that the onCreate method is the first things that runs when your application is starting and it runs on the main/UI thread. This means that if you do long tasks in your init() method your UX will be poor, not to mention that you are risking an ANR exception.

    The solution for that is simple:

    1. Keep your onCreate short
    2. Create a BG thread and use it to run all initialization code
    3. Show a “Splash”/”Welcome” screen with the a proper progressbar while the BG thread is running.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a big solution containing that much projects..i need to find a specific
I need to find/create an application that will create employee web usage reports from
I have a large amount of data that I am pulling from an xml
I already googled around to find a solution for my need, with no success.
Per-frame I need to allocate some data that needs to stick around until the
I need to find a good backup solution for the site I have hosted
I need to find a point that is a visual center of an irregularly
I know that this is discussed a lot but I don't find solution of
I've been trying to find a host that has output_buffering enabled and my host
I need to copy large resultset from one database and save it to another

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.