Well, I assumed that it should be as simple as
fragmentManager.beginTransaction().replace(R.id.container, otherFragment).commit();
Should do that, but indeed not.
Even fragmentManager.beginTransaction().remove(fragment);
doesn't kill it.
Other fragment loads, but in the Fragment I'm trying to kill there is a SensorEventListener which continue to react even after the fragment was replaced. I can hear the sounds and stuff.
Of course, I can make a boolean and switch it, but it seems to me there should be another way to simply destroy this object.
This is how I init fragment :
public static BaseGameFragment newInstance(int mode) {
BaseGameFragment.mode = mode;
BaseGameFragment fragment = new BaseGameFragment();
return fragment;
}
I also try to call onDestroy();
but it doesn't stop sensor's reaction and, therefore, all other processes within fragment.