I am experiencing some weird behavior with an android app I have been working on, here is what happens:
- I use the app for a while, works fine without problems
- I "pause" the app by clicking on the android home button
- I use some other apps on the phone for a few mins
- I go back to my app and it seems like its in a very weird state, the FragmentActivity is lost, but the Fragment that was being displayed last it still shown. When i do a call "getActivity()" from the Fragment it returns null which causes problems (because i need a reference back to the FragmentActivity.
Any idea why the FragmentActivity is lost after the app is paused after a while, i assume its some sort of garbage collection issue, but normally wouldn't the whole app be destroyed not just the FragmentActivity?
Some things to note:
- I am using the compatibility library
- I am using viewpage indicator (but i dont see this as being anything to do with the issue) - https://github.com/JakeWharton/Android-ViewPagerIndicator
Note: i can also reproduce this problem easily when i remove my android:configChanges="orientation|keyboardHidden|screenSize"
from the activity element in the manifest and do a orientation change.
So i assume its not maintaining state of the views after activity recreation.
onSaveInstanceState
and onRestoreInstanceState
are called ok, and setRetainInstance(true);
is set on the fragment so im not sure why this is happening.