I have three activities Main, Item, and ItemDetail
Item has Main set to Parent in manifest
<activity
android:name=".Activities.Item"
android:parentActivityName=".Activities.Main"
/>
ItemDetail has Item set to Parent in manifest
<activity
android:name=".Activities.ItemDetail"
android:parentActivityName=".Activities.Item"
/>
Here is what the activity flow should look like visually
Main > Item > ItemDetail
Both Item and ItemDetail extend from BaseActivity
public class Item extends BaseActivity { ... }
public class ItemDetail extends BaseActivity { ... }
BaseActivity displays and enables home button
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Now here is the problem: when pressing BACK button from ItemDetail activity, Item is brought to the foreground which is the expected behavior, right? However, when HOME button is pressed from ItemDetail activity, Item activity's onDestroy and onCreate are called, indicating (obviously) that Item activity is being destroyed before being recreated.
My question is why is Item activity destroyed and when pressing home button from ItemDetail but not back button. This makes no sense to me.
TL;DR
My app is crashing when pressing home because I expected Item to remain on the activity stack and maintain state, but activity is unexpectedly destroyed resulting in a null pointer error.
edit
Yes, I have onSavedInstance state implemented and working, it's just that the saved states is gone, calling this line from Item activity's onCreate returns true
null == savedInstanceState; // returns true