0

How can I write singleton to work through several processes? Is it possible? For example I have code that works with Remote Service in Android. How can I write singleton for this purpose?

UPDATE:

public enum Singleton {
    INSTANCE;

    int a = 0;

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }   
}



    void doFromFirstProcess(){
        Singleton.INSTANCE.setA(1);
    }

    void doFromSecondProcess(){
        Singleton.INSTANCE.getA(); //0
    }

Why does it not work? What is wrong with my code?

user1074896
  • 1,025
  • 2
  • 15
  • 27
  • 1
    I've answered it, but need to know more about your goal to give you alternative solution. – weston Feb 08 '12 at 12:16
  • I register some data in Splash Screen activity and then use this data in methods that I call from remote service. – user1074896 Feb 08 '12 at 12:43
  • Perhaps you can use `SharedPreferences` and maybe this will help you to that: http://stackoverflow.com/questions/7139421/multiple-apps-sharing-same-data-directory If not maybe start a new question on how to share data in android. – weston Feb 08 '12 at 13:13

1 Answers1

2

No, seperate processes do not share any memory.

weston
  • 54,145
  • 21
  • 145
  • 203