Below is my code from my activity. I call setKey() to set the key, but when I use getKey() it returns "";
public class SharedData {
// This is a singleton class that provides a global data
private SharedData instance = null;
private SharedData() {
}
// Data to be shared
private String key = "";
public static SharedData getInstance() {
instance = new SharedData();
return instance;
}
public String getKey() {
return key;
}
public void setKey(String skey) {
key = skey;
}
}
It seems that every time you are creating new instance for SharedData everytime
now you need to below lines to use the same instance every time: