public class
Activity
since:API Level 1
extends ContextThemeWrapper
implements ComponentCallbacks KeyEvent.Callback Layoutlnflater.Factory View.OnCreateContextMenuListener Window.Callback
java.lang.Object
↳ android.content.Context
↳ android.content.ContextWrapper
↳ android.view.ContextThemeWrapper
↳ android.app.Activity
Known Direct Subclasses
ActivityGroup, AliasActivity, ExpandableListActivity, ListActivity
Known Indirect Subclasses
LauncherActivity, PreferenceActivity, TabActivity
Class Overview
An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View). While activities are often presented to the user as full-screen windows, they can also be used in other ways: as floating windows (via a theme with windowIsFloating set) or embedded inside of another activity (using ActivityGroup). There are two methods almost all subclasses of Activity will implement:
- onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.
- onPause() is where you deal with the user leaving your activity. Most importantly, any changes made by the user should at this point be committed (usually to the ContentProvider holding the data).
To be of use with Context.startActivity(), all activity classes must have a corresponding <activity> declaration in their package's AndroidManifest.xml.
The Activity class is an important part of an application's overall lifecycle, and the way activities are launched and put together is a fundamental part of the platform's application model. For a detailed perspective on the structure of Android applications and lifecycles, please read the Dev Guide document on Application Fundamentals.
最終更新:2009年10月16日 23:30