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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:33:26+00:00 2026-06-13T19:33:26+00:00

The class contain this parameter like thie public class Global { public static String

  • 0

The class contain this parameter like thie

public class Global {
    public static String USER_ID = "";
    public static String USER_NAME = "";
    public static String USER_PASSWORD = "";
}

the USER_ID,I set once when do login.(for example Global.USER_ID = “12345”).
And a thread running on the background do that every 5 minute post some data(contains this USER_ID) to webservice.

the question is
when the thread running long long time (about one day).
I found the parameter USER_ID return back to “”, is not the “12345”.

Why???

anyone know 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-13T19:33:27+00:00Added an answer on June 13, 2026 at 7:33 pm

    I think your class is removed from the memory by class loader (during GC) and it is loaded next time you use Global class.

    My Suggestion will be to use Singelton class for this you can have something like this

    public class Global {
        public String USER_ID = "";
        public String USER_NAME = "";
        public String USER_PASSWORD = "";
    
        //constructor 
       private Global(){
        // just to prevent object creation from outside
       }
        //static reference
        public static Global global=null;
        public Global getInstance(){    
         return ((global!=null)? global : (global=new Global()) ;
        }
    }
    

    Now wherever you want to use this class you can get this object, the singelton logic ensures that their is only one object which is shared among all.

    You can get the reference in your threads using

    global = Global.getInstance();
    

    Now you can use variables i.e. USER_ID using global.USER_ID

    Since you have a reference of global object GC will not remove that from memory till your thread is alive.

    NOTE
    I have used public variables just for the illustration however they are not recommended in most cases.

    EDIT

    For saving user data I recommend SharedPreferences and you can use them as follows:-

    private final String YourAppName_PREFS_NAME = "chooseAMeaningFulName";
    private final String YourAppName_USERNAME = "username";
    private final String YourAppName_PASSWORD = "password";
    
     /*This function will save the user name and password for providing Automatically login in future*/
    
           public void saveUserData() {
              if ( rememberMeChckbox.isChecked() ) {
                //      Log.i("loginFrag", "Saving userName: Pass " + userName + " : " + password);
                loginActivity.getSharedPreferences(YourAppName_PREFS_NAME, Context.MODE_PRIVATE).edit().putString(YourAppName_USERNAME, userName)
                      .putString(YourAppName_PASSWORD, password).commit();
              } else {
                loginActivity.getSharedPreferences(YourAppName_PREFS_NAME, Context.MODE_PRIVATE).edit().remove(RBR_USERNAME).remove(RBR_PASSWORD).commit();
              }
            }
    
            /*This function returns the previous data from the SharedPreferences and fills the UserName and Password Text Box*/
            private void getPreviousUserData() {
              SharedPreferences preferences = loginActivity.getSharedPreferences(YourAppName_NAME, Context.MODE_PRIVATE);
              userName = preferences.getString(YourAppName_USERNAME, null);
              password = preferences.getString(YourAppName_PASSWORD, null);
              //      Log.i("loginFrag", "Got userName: Pass " + userName + " : " + password);
              if ( userName != null ) {
                uText.setText(userName);
              } else {
                uText.setText("android");
              }
              if ( password != null ) {
                passText.setText(password);
              } else {
                passText.setText("android");
              }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is a python file named BasePlat.py which contain something like this: class BasePlatform(SimObj):
I have a class that contains a boolean field like this one: public class
say, I have a partial class that contains a custom property like this public
I have a class that contains two methods like these: public String getFoo(Int32 a)
I have class like this below shown. which contains the shopping items where the
I have a class in crawl.py that's like this: from myapp.crawl import ScrapyCommand class
I have this custom filter for compress the output of my pages: public class
Each inherited class's method need different type of parameter. In this case, how should
I have a class that contains this class method: def self.get_event_record(row, participant) event =
I have a class that inherits from a base class (this contains a lot

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.