I want to monitor if the fragment has been added to the activity. I have instance of activity, which I am using in non-activity class to monitor if any fragment is added to activity. I have created Flowable to watch the count change which is as follows.
FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
Flowable<Integer> mIntegerObservable = Flowable.just(fragmentManager.getBackStackEntryCount());
mIntegerObservable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(fragC -> {
Log.e("Count:", ""+fragC);
}, error -> {
//do something on error
});
Subscribe is being called only once where I have placed this code and the value logged is 0, Now if I add fragment inside activity subscriber is not not being triggered. How can I achieve this?