After much research I have come to the conclusion that it is not possible to manipulate fragments on Android when the Activity is resumed. I have tried, as per the mentioned blog post, onPostResume() and onResumeFragments() to pop fragments from the backstack, and both result in intermittent crashes when released to production.
The downside to this reality is that if you wanted to, for example, display an end of level fragment, followed by an interstitial advertisement, followed by the next level (as a different fragment to the end of level fragment) then it is not possible to use fragments.
For my personal situation, I removed all fragments from my application. I keep using layouts, because editing the UI in XML is useful, but the Fragment lifecycle is unusable in its current state so I rolled my own "fragment" subsystem, but better because it can be manipulated from the Activities onResume.
I hope that one day Google will fix this because it makes developing for Android really unpleasant. Anyway, if anyone needs to use fragments, but doesn't like the typical onSaveInstanceState exception that you will invariably get, here is my "GameScreen" implementation (it's like a fragment, only better)
/**
* GameScreen
*/
public class GameScreen {
private int id;
private View view;
private ViewGroup viewGroup;
protected MainActivity mainActivity;
public GameScreen(MainActivity mainActivity, int id) {
this.mainActivity = mainActivity;
this.id = id;
}
public void create(LayoutInflater layoutInflater, ViewGroup viewGroup) {
this.viewGroup = viewGroup;
view = layoutInflater.inflate(id, viewGroup, false);
viewGroup.addView(view);
}
public void show() {
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View v = viewGroup.getChildAt(i);
if (v != view) {
v.setVisibility(View.INVISIBLE);
}
}
view.setVisibility(View.VISIBLE);
}
}