My education application is having a tab host with 6 to 7 tabs with landscape and portrait modes support. In each and every activity associated with a tab, I am showing some student records in list view, with some check boxes for selection and some rating bars, buttons etc. I am getting these student records from remote server through web service call. For some reasons, my app will show one initial relative layout with some buttons after doing some actions/searches It will show results in list view, upon clicking list item or buttons in list view I am showing some other layout. This applies to all activities in tab host.
If user changes orientation I have to restore the same state or same screen means if user previous seeing list of records I have to show list of records, If initial I have to show initial only. I don't want to force stop android destroying activity on orientation change or overriding public Object onRetainNonConfigurationInstance ()
.As suggested in some blogs and android doc's these may cause problems in later operations. What I did is simply saving all required info like which screen 1 or 2 or 3, Text view labels and all primitive data types in onSaveInstanceState
Bundle and restoring them in onRestoreInstanceState
. Also I am writing my custom search results Object array to file and retriving and deleting it between onSaveInstanceState and onRestoreInstanceStates. As my search results has 100's of objects and I am storing huge volumes of primitive data type lists, which increasing heap size rapidly when user rapidly rotates the device.
What is the best way to deal with it
1) persisting in onSaveInstanceState and onRestoreInstanceStates, which makes my screen blank for some time and increasing heap size, un necessarily performing save and restore when user rotating multiple times
2) keeping all needed data some where as static, as it is not local to activity, it won't destroy
3) keeping all needed data by extending Application class?