Home Forum
Welcome, Guest
Username Password: Remember me

Forcing onSaveInstanceState() to be called
(1 viewing) (1) Guest
Discussion related to creating Android software
  • Page:
  • 1

TOPIC: Forcing onSaveInstanceState() to be called

Forcing onSaveInstanceState() to be called 2 years, 9 months ago #204

I understand this will be called when the app is backgrounded *and* the system needs to kill the process. What I find in the emulator is there are apparently enough resources such that the app is restored immediately upon being foregrounded without needing to make this call. So how can I test it please?
  • ticktock
  • OFFLINE
  • Professor
  • Posts: 79
  • Karma: 6

Re:Forcing onSaveInstanceState() to be called 2 years, 9 months ago #209

This call is made when switching orientation, for example a video player application is running and the user tips the device to view the video landscape, this results in the Activity being torn down and another created.

The video player uses this call to remember the position of the video so that when the new activity starts the video resumes.
  • mmoore
  • OFFLINE
  • Examiner
  • Posts: 22
  • Karma: 1

Re: Forcing onSaveInstanceState() to be called 1 year, 5 months ago #340

Another way to force onSaveInstanceState() to be called is to set up the emulator to kick your app out of memory. I find this is a more realistic way to test: your app gets killed, and all the variables are destroyed. To make this happen, in the emulator, go to Dev Tools; Development Settings; click on the drop-down box "app process limit", and set it to 1. Start your app, hit home, then start contacts or some simple app. You may see a kill message in logcat.
  • Lucy
  • OFFLINE
  • Freshman
  • Posts: 1
  • Karma: 0
The following user(s) said Thank You: ticktock

Re: Forcing onSaveInstanceState() to be called 1 year, 5 months ago #341

That's a great tip I didn't know about - sincere thanks!
  • ticktock
  • OFFLINE
  • Professor
  • Posts: 79
  • Karma: 6
  • Page:
  • 1
Time to create page: 0.19 seconds
Copyright © 2012 Android Academy. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 
Glossary
We have 23 guests online