I have MainActivityFragment from where I start DetailActivity with below code:
private final CurrencyListAdapter.ClickListener itemClickListener
= new CurrencyListAdapter.ClickListener() {
@Override
public void onItemClick(int position, View v) {
Intent intent = new Intent(getActivity(), DetailActivity.class);
String code = mCurrencyList.get(position).getCode();
intent.putExtra(Constants.SELECTED_CODE_KEY, code);
startActivity(intent);
}
};
After that from my DetailActivity I start my DetailActivityFragment with below code:
if (savedInstanceState == null) {
DetailActivityFragment fragment = DetailActivityFragment.getInstance(code);
getSupportFragmentManager()
.beginTransaction()
.add(R.id.detail_container, fragment)
.commit();
}
Also I am retaining the instance state within my MainActivityFragment. However, while hitting back button from DetailActivityFragment, onCreateView method of my MainActivityFragment is called and I am not able to restore instance state, because saveInstanceState method is not executed and thus the savedInstanceState is null. I am very curious why this happening. This is not happening in other project wich has the same logic. I will be very thankful if anyone could help me.