Saturday, February 22, 2014

Global variables exist in the application or other types of static variables


Before I deal with the global variable exists android own application, such as the user's login user name and other information, but today find someone to keep custom classes, such as the definition of a class in a static variable XX store I think This way is not good, because since android has saved global variables application, why use other class static member variables to store it, but if it is feasible that way, and with them also convenient than application in existence. Is it really the same?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Things on a global instance of a class inside such Config.java
Need only instantiated once.
Or put SharedPerferences inside,
Reply:
 
class Config {
public static Config config;
public static Config getConfigInstance () {/ / single instance
if (config == null) {
config = new Config ();
}
return config;
}

public String username;
public String sessionId;
..........
}

Reply:
I now have the habit on a custom static class, and then use a static set, get methods
Reply:
reference to the second floor birdsaction reply:
 
class Config {
public static Config config;
public static Config getConfigInstance () {/ / single instance
if (config == null) {
config = new Config ();
}
return config;
}

public String username;
public String sessionId;
..........
}

This seemingly more convenient
Reply:
Looks like this is the case, it seems that application was really tasteless.

No comments:

Post a Comment