Saturday, September 28, 2013

Android Tutorial: Pausing and Resuming an Activity


On Google Android's Pausing and Resuming an Activity, things I learned could greatly improve or heal the performance of my current Android application. The most important things I learned are what should be done in onPause() and what should not be done in onPause(). These things will be listed below.

SHOULD Do in onPause():

  • Stop animations or other ongoing actions that could consume CPU.
  • Commit unsaved changes, but only if users expect such changes to be permanently saved when they leave (such as a draft email).
  • Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life while your activity is paused and the user does not need them.
SHOULD NOT Do in onPause():
  • NOT Store user changes (such as personal information entered into a form) to permanent storage, unless the auto-save function is needed to be implemented here.
  • NOT Perform CPU-intensive work, such as writing to a database. (This should be done in onStop()).
For onResume(), as the tutorial said, onResume() really depends on what are stopped in onPause() function, if anything is stopped or released in onPause(), then onResume() is the place to reinitialize and restart it if it's needed.

No comments :

Post a Comment