It ple, when a recently revealed activity discusses the whole monitor

It ple, when a recently revealed activity discusses the whole monitor

If your craft no longer is visually noticeable to the consumer, it has inserted the fresh Eliminated condition, in addition to program invokes the fresh onStop() callback. The device may also phone call onStop() in the event the interest possess complete running, and that is about to feel ended.

If the interest actions to the stopped county, one lifecycle-alert part tied to new activity’s lifecycle will have the fresh new On the_Stop event. That is where the new lifecycle components normally prevent one possibilities one does not need to focus on given that parts is not obvious on display.

About onStop() means, the application should release otherwise to switch resources which are not required while the application is not visually noticeable to an individual. Such as for instance, your software you’ll stop animated graphics otherwise option regarding fine-grained so you’re able to rough-grained location status. Using onStop() in the place of onPause() ensures that UI-related really works continues, even if the representative is actually seeing your own hobby in the multiple-window setting.

You should also fool around with onStop() to do seemingly Cpu-intensive shutdown functions. Particularly, if you can’t select a more opportune time to save yourself information to a database, you can exercise during onStop() . The next example shows an utilization of onStop() one to saves the brand new belongings in a great write notice so you’re able to chronic shop:


Note, brand new password try significantly more than uses SQLite in person. You will want to as an alternative play with Place, a persistence library that provides an abstraction layer over SQLite. For more information on the many benefits of playing with Area, and how to spiritual singles implement Place on the app, understand the Room Time and effort Library guide.

When your hobby comes into this new Prevented condition, the experience object is actually kept resident into the memory: It maintains all the county and you can member pointers, it is maybe not attached to the window manager. When the hobby resumes, the game recalls this post. You don’t need to re-initialize parts that were composed during some of the callback tips before the brand new Resumed state. The machine together with monitors the modern county per Look at target from the concept, anytime an individual registered text to your an enthusiastic EditText widget, you to blogs try employed so you won’t need to save your self and you will restore they.

Note: When your craft is actually averted, the machine might ruin the procedure containing the activity when the the system should get well thoughts. Even when the system destroys the method given that pastime was averted, the system however holds the condition of the view stuff (such as for instance text message inside the an EditText widget) inside the a bundle (a great blob off trick-really worth sets) and restores her or him if the member navigates back to the activity. To find out more on repairing a task to which a person yields, see Preserving and you will repairing hobby condition.

From the Prevented county, the game sometimes returns to interact into the associate, or even the pastime is finished powering and you can goes away completely. Whether your interest comes back, the system invokes onRestart() . In case your Craft is finished powering, the device calls onDestroy() . Another part explains the onDestroy() callback.


  1. the experience was finishing (as a result of the member totally dismissing the game otherwise because of finish() becoming named with the interest), otherwise
  2. the machine was briefly ruining the game because of a setup changes (eg device rotation otherwise multiple-windows means)

If the pastime movements with the missing condition, any lifecycle-aware parts linked with the newest activity’s lifecycle will receive the newest Into the_Wreck event. This is where this new lifecycle portion normally clean up anything they has to until the Craft is actually shed.

In the place of placing reason on your own Passion to choose why they is being forgotten you can use a good ViewModel object so you’re able to contain the relevant take a look at data for the Hobby. Whether your Craft should be reproduced on account of an effective setting alter the ViewModel need not do just about anything due to the fact it will be managed and made available to the following Passion instance. If your Activity is not going to become recreated then ViewModel will receive the newest onCleared() strategy called where it will tidy up one investigation it takes so you’re able to in advance of getting destroyed.

Written by