E before onpause save state in a bundle object

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y stack, with user input going to it COMP 4521 (Muppala) Android Overview 7 Ac'vity Lifecycle •  When are the methods called in an ac'vity's overall lifecycle? –  onPause() •  Called when the system is about to start resuming another ac'vity •  This method is typically used to commit unsaved changes to persistent data, stop anima'ons and other things that may be consuming CPU, and so on –  onStop() •  Called when the ac'vity is no longer visible to the user •  This may happen because it is being destroyed, or because another ac'vity has been resumed and is covering it –  onDestroy() •  Called before the ac'vity is destroyed COMP 4521 (Muppala) Android Overview 8 Saving Ac'vity State •  When system shuts down an ac'vity, user may expect to return to the ac'vity in its previous state •  Make use of two methods implemented within the ac'vity to save and restore state: –  onSaveInstancestate(): Android calls this before making the ac'vity vulnerable to being destroyed (i.e. before onPause()) •  Save state in a Bundle object –  onRestoreInstanceState(): Bundle passed both to onCreate() and the onRestoreInstanceState() which is called just before onStart() to recreate the captured state –  Both methods are not part of lifecycle, as they need not be called when the user inten'onally destroys the ac'vity COMP 4521 (Muppala) Android Overview 9 Saving Ac'vity State COMP 4521 (Muppala) Android Overview 10 Coordina'ng Ac'vi'es •  When one ac'vity starts another, they both experience lifecycle transi'ons –  One pauses and may stop, while the other starts up. –  On occasion, you may need to coordinate these ac'vi'es, one with the other. •  The order of lifecycle callbacks is well defined, par'cularly when the two ac'vi'es are in the same process. For example if Ac'vity A starts Ac'vity B: 1.  A's onPause() method is called. 2.  B's onCreate(), onStart(), and onResume() methods are called in sequence. 3.  Then, if A is no longer visible on screen, its onStop() method is called. COMP 4521 (Muppala) Android Overv...
View Full Document

Ask a homework question - tutors are online