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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:30:12+00:00 2026-06-18T14:30:12+00:00

For storing runtime data in my app I have a class with two static

  • 0

For storing runtime data in my app I have a class with two static variables:

public class App {
  public static ClementineConnection mClementineConnection = null;
  public static Clementine mClementine = null;
}

Those are initialized in the onCreate Method of the first Activity. This Activity does nothing but starting other activities depending on a state (is the app connected to server).

If the App is idle or running in the background with a notification, sometimes a NullPointerException occurs in the other onCreate Methods when accessing one of the static variables. Somehow they get garbage collected.
The App has a Service with a Thread running in the Background, so I thought there must be a reference all the time.

Do you know how I can prevent those static variables from being garbage collected? While the app is connected to the server, the information must be available. Creating a new instance (eg. Clementine.getInstance()) is not an option.

If you want to have a look at the code: https://code.google.com/p/clementine-remote-android/source/browse/

  • 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-18T14:30:13+00:00Added an answer on June 18, 2026 at 2:30 pm

    What I think you need to do, is use Android Application Class.

    There you can share and persist data to all of your activities, and initializes the variables there. You can make your App Class extend it.

    public class App extends Application {
        public static ClementineConnection mClementineConnection = null;
        public static Clementine mClementine = null;
    

    And in each of the activities:

    App app = ((App)this.getApplication());
    

    Also, you have to declare it in your manifest;

    <application android:name="de.qspool.clementineremote.App" ...></application>
    

    Look at those answers on the subject:

    • Using the Android Application class to persist data

    • Use Application class for global variables

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

Sidebar

Related Questions

I'm using app engine datastore so I have entity like this. @PersistenceCapable public class
Suppose I have this annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Name { String value(); }
We are trying to allow the app to have its culture set at runtime
I have an app that I want to use to store different people's data.
I have a Java Runtime.getRuntime().exec() problem. I run my java app on Linux and
I have this problem where I can't get my dynamic data web app to
How to rewrite Webconfig connection string at runtime.I have input textbox for Server,UserName and
I want to change the app.setting connection string at the run time. I have
I have extended the spinner class in order to customize it, but i can't
Using Visual Studio 2008 and VB.Net: I have a working web app that uses

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.