[Points] Activities

source page: http://developer.android.com/guide/components/activities.html

Activities

  • an application component that provides a screen
  • "main" activity for launching the application for the first time
  • each activity can start another activity
  • tasks and back stack
  • when stopped,release any large objects
  • Activities that you don't want to make available to other applications should have no intent filters and you can start them yourself using explicit intents

Lifecycle

 

 

  • onCreate() should initialize the essential components setContentView()
  • onResume() foreground of screen
  • onPause() first indication that user leaving activity where you should commit an changes (keep data)
  • onStop() completely obscured by another activity it can be killed by system when momory is needed elsewhere may be not called
  • onDestroy() may be not called

Note: An activity that's not technically "killable" by this definition in table 1 might still be killed by the system—but that would happen only in extreme circumstances when there is no other recourse. When an activity might be killed is discussed more in the Processes and Threading document.

Saving activity state

 

 

  • onSaveInstanceState() save state of activity in Bundle passed to onCreate() or onRestoreInstanceState()

Note: There's no guarantee that onSaveInstanceState() will be called before your activity is destroyed, because there are cases in which it won't be necessary to save the state (such as when the user leaves your activity using the Back button, because the user is explicitly closing the activity). If the system calls onSaveInstanceState(), it does so before onStop() and possibly before onPause().

posted @ 2013-11-25 18:01  Jsaint  阅读(115)  评论(0)    收藏  举报