0

I've a singleton class which looks something like this,

public class MyHomeFactory {

    public static final String TAG = "sddsd";
    private static MyHomeFactory myHomeFactory = null;

    private MyHomeFactory() {
        Log.i(TAG, "Inside my home factory");
    }

    public static MyHomeFactory getInstance() {
        if(myHomeFactory == null) {
            myHomeFactory = new MyHomeFactory();
        }
        return myHomeFactory;
    }
}

I'm invoking MyHomeFactory.getInstance() in my application class and in my service class (which runs under different process) something like this,

public class CornetApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "The value of instance is : " + MyHomeFactory.getInstance());
    }
}

and from service inside it's onBind like,

@Override
    public IBinder onBind(Intent intent) {
        return new IMyAidlInterface.Stub() {
            @Override
            public void printTime(long time) throws RemoteException {
                Log.i(TAG, "Instance value is : " + MyHomeFactory.getInstance());
            }
        };
    }

Service declaration in AndroidManifest looks something like this,

<service
            android:name=".OnDisConnectedService"
            android:enabled="true"
            android:exported="true"
            android:process=":separate_process"/>

To my surprise both the instance value is printed something like this,

com.example.circa.MyHomeFactory@63b959e

in place of getInstance(). How this instance is shared between process? I'm getting confused here.

Tom Taylor
  • 3,344
  • 2
  • 38
  • 63
  • You should take a peek at [Does singleton means hashcode always return the same?](https://stackoverflow.com/questions/12987558/does-singleton-means-hashcode-always-return-the-same) – atomskaze Dec 17 '19 at 18:58
  • Hmmm... I would like to see the raw logcat, the entire lines (that include the time and the PID/TID), something seems fishy here... – greeble31 Dec 17 '19 at 19:55

0 Answers0