I have an app (appA) that inflates a layout (layout1) and lets the user do stuff before it replaces that layout with another (layout2) from which the user launches another app (appB) via startActivityForResult
appB is a Unity3D based monstrosity that taxes the limits of the device's memory/processing power and so consequently while appA is in the background it frequently gets cleaned up by Android.
When appB finishes Android re-creates appA for me but it does so in a way that is confusing.
Namely: it calls onCreate but it launches with appA still displaying layout2, the layout that it inflated just before it went to appB.
This is confusing because onCreate reinitializes all my variables and seems to be starting from scratch but somehow preserves the state of still displaying layout2.
This is clearly different than the behavior I would get if I were to call finish() on appA when I launched out to appB and then had appB start appA from scratch where it would (and does) first inflate layout1.
My problem is that this behavior is not consistent. A lot of the time Android manages appB without needing the appA memory space and debugging this is really tough.
I'm wondering if there's some manual way (via Android Studio or in code) to provoke an Android clean-up of appA while I'm in appB to be able to see and test the side-effects of coming back to appA after it's been brought back to life by Android.