Why should I bindService if I can make it singleton-like?

Viewed 41

If I have some service like

public class FooService extends Service {

    private static FooService mInstance;

    public static FooService getCurrentInstance() {
        return mInstance;
    }
   
    public FooService() {
        mInstance = this;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // ...
        return START_REDELIVER_INTENT;
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    public class LocalBinder extends Binder {

        public FooService getService() {
            return FooService.this;
        }
    }
}

Is it still required (in some case) to use bindService from an activity to access this service ? Or it can be used using getInstance() if the service is already running?

0 Answers
Related