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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:24:15+00:00 2026-06-12T16:24:15+00:00

I have a singleton in Android for data loaded from xml. It gets recycled

  • 0

I have a singleton in Android for data loaded from xml. It gets recycled from time to time and I don’t understand why. Singleton should exist through the lifetime of app process by my knowledge. Here’s my singleton:

public class DataLib {

    public static CategoryList categories = new CategoryList();
    public static RegionList regions = new RegionList();
    public static CompanyTypeList types = new CompanyTypeList();
    public static SearchData searchData = new SearchData();
    public static CompaniesList companies = new CompaniesList();

    private static RegionData currentRegion;

    private static final DataLib INSTANCE = new DataLib();

    protected DataLib() {
    }

    public static DataLib getInstance() {
        return INSTANCE;
    }

    public static void loadData() {
        loadCategories();
        loadRegions();
        loadTypes();
    }

    /* ... some more static functions are here ...*/
}

As you can see it is not instantiated by any activity directly but rather by the process itself. The data are loaded by calling DataLib.loadData() when the application starts = activity which will end when the data are loaded.

I cannot tell for sure what triggers the recycling – sometimes app needs to stay in the background for longer time, sometimes it’s in a few minutes. I am logging the pointer of the DataLib class so I can tell that it truly changed = got recycled.

Any ideas? Thanks.

EDIT: Answer is partially in marked answer + comments to it.

  • 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-12T16:24:16+00:00Added an answer on June 12, 2026 at 4:24 pm

    It gets recycled from time to time and I don’t understand why.

    Android will terminate your process “from time to time”.

    sometimes app needs to stay in the background for longer time, sometimes it’s in a few minutes

    The OS and the user can get rid of your process whenever they feel like it. Singletons and other static data members need to be caches for persistent data, loading that data using background threads and the like.

    If there is particular work that you are doing in the background, you should be using a Service for that, to indicate to the OS that you are doing work in the background independent of any activities. That does not prevent Android from terminating your process (e.g., at user request), but it will make it a bit less likely to terminate your process on its own (i.e., the OS will tend to choose other processes).

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

Sidebar

Related Questions

I have an Android Application that has the AndroidManifest.xml listed below. After uploading to
I have a threading, singleton, android question. So let's say we have the following
I have a singleton class that inherits from sprite so that it can access
I have an activity which I want to use to display data sent from
I have been trying to invoke my application from browser on android 3.1 (Honeycomb)
I am developing for android using android annotations. I have a singleton observable object
I have a Singleton to manage some variables I need in various places in
I have a singleton class for global access to config information. This singleton class
I have a Singleton that is accessed in my class via a static property
I have a singleton object that use another object (not singleton), to require some

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.