Friday, September 27, 2013

Android Tutorial: Starting an Activity

To rebuild my solid background of Android Development, I recently went through the whole tutorial provided from Google Android. Then, here comes the first lesson of "The Activity Lifecycle Management", to start an activity.

Though, most of staff on the page is known for me, there are still things I learned today here. Here follows a very important image which explains all the piece of Activity Lifecycle.



1st, onCreate() and onStart() function goes list a swift.

2nd, Most of UI and class member initialization work are done in onCreate() function.

3rd, Implementing your activity lifecycle methods properly ensures your app behaves well in several ways, including that it:
  • Does not crash if the user receives a phone call or switches to another app while using your app.
  • Does not consume valuable system resources when the user is not actively using it.
  • Does not lose the user's progress if they leave your app and return to it at a later time.
  • Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.
4th, While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.

5th, onDestroy(), this function is barely called in the code, unless the app has some background running thread, which might cause memory leak potentially.

6th, Note: The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one: when you call finish() from within the onCreate() method. In some cases, such as when your activity operates as a temporary decision maker to launch another activity, you might call finish() from within onCreate() to destroy the activity. In this case, the system immediately calls onDestroy() without calling any of the other lifecycle methods.

No comments :

Post a Comment