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.