Final answer:
To preserve transient-state data in an Android application, you need to override the onSaveInstanceState() and onRestoreInstanceState() or onCreate() methods. These methods are used to save and later restore the activity's state.
Step-by-step explanation:
To preserve transient-state data in an Android application when the activity is paused or stopped, you typically need to override two methods: onSaveInstanceState() and onRestoreInstanceState() or onCreate(). These methods are part of the activity lifecycle and are called by the Android system to allow you to save and restore the activity's state.
When an activity is partially obscured, or even completely destroyed, it may need to save certain state data to be restored later. onSaveInstanceState() is invoked before the activity becomes vulnerable to being destroyed by the system. In this method, you can save the state to a Bundle object. Typically, you would put any dynamic data or transient UI state in the Bundle to be pulled out later.
When the activity is re-initialized, the data saved in onSaveInstanceState can be restored using onRestoreInstanceState(), which is called after the onStart() method, or the onCreate() method if the activity was completely destroyed. Alternatively, you can also restore your activity's state in the onCreate() method with the Bundle that is passed to it, if you check for the existence of this Bundle.