This should run Android OS automatically. You can enable the “do not continue” developer option to always simulate this behavior (destroying your activity) when your activity goes to the background. After that you can start debugging. Some things to check:
In onCreate activity do you call super onCreate with saveInstanceState?
If you set a breakpoint at the beginning of onCreate when you “come back” into action, is there a state of the saved instance?
Where do you create fragments? Do you recreate them manually (you shouldn't)?
Are your fragments hardcoded in the layout or replaced in the layout (replacing the container view)?
* EDIT *
From your answer, I get that this is a problem, you say: "At the end of onCreate, I replace the fragment with the fragment transaction and thus load the first application fragment" =>, you should not do this when the saved InstanceState is not null. Otherwise, you destroy what already exists from the saved state.
Check here: https://developer.android.com/training/basics/fragments/fragment-ui.html
Note the return when savedInstanceState does not matter.
public class MainActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news_articles);
source share