android 的API的Activity翻译

一、继承结构

    java.lang.object-->android.content.Context-->android.content.ContextWrapper-->android.view.ContextThemeWrapper-->android.app.Activity

二、所有已实现的接口

ComponentCallbacks,keyEvent.Callback,LayoutInflater.Factory,View.OnCreateContextMenuListener,Window.Callback

三、直接已知子类

ActivityGroup,AliasActivity,ExpandableListActivity,ListActivity

翻译:

public class Activity extends ContextThemeWrapper implements LayoutInflater.Factory,Window.Callback,KeyEvent.Callback,View.OnCreateContextMenuListener,ComponentCallbacks

一个activity是一个单例,用户能够在上面处理一些事情。几乎所有的activites都与用户进行互动,因此Activity类使用方法setContentView(int)放置UI组件到创建的窗口上。与此同时,activies通常以全屏的形式展现在windows上,也可以使用其他的方法,例如漂浮在window上(通过theme使用andorid.R.attr#windowIsFloating 设置)或者嵌入到其他的acticity(使用ActivityGroup).Activity的子类需要实现至少两种方法

onCreate(andorid.os,Bundle)用来初始化你的activity.最重要的是,在这里你通常调用setContentView(int)方法来布置你的资源文件到UI上,且使用findViewById(int)来检索widgets中的UI,你能够使用带来来进行互动。

onPause()用来处理用户离开activity。最重要的,任何由用户进行的改变在此时被确认(通常到ContentProvider保持数据)

使用Context.startActivity(),所有的activity类必须有一个相应的<activity>在AndoridManifest.xml中声明。

Activity类在应用的整个生命周期中是很重要的一部分,activitys的简历和整合是应用模型平台的一个基础功能。关于安卓应用数据结构的详细观点,请阅读Dev Guid文档在Application Fundamentals.

Topics covered here:

1、Activity Lifecycle

2、Configuration Changes

3、Starting Activities and Getting Results

4、Saving Persistent State

5、Permissions

6、Process Lifecycle


1 Activity Lifecycle

所有的系统中的Activities以activity stack(栈)的形式管理。当一个activity启动后,它被放置在栈的最顶端,且成为运行中的activity----之前的activity通常放置在栈的下边,在新的activity存在的情况下是不会出现到前台的。

一个activity具有四个本质特点

如果activity在屏幕的前端,他处于被激活或者运行状态。

如果activity失去焦点,但是仍然可见(就是一个新的非全屏尺寸或者转场的activity在你的activity之上获取焦点),他会暂停。一个暂停的activity是完全活着的(他保持所有的状态和成员信息且依然接近window管理者),但是可能被紫铜在低内存状态下杀死。

如果activity被另一个activity完全遮蔽,他就会停止。他依然会保持所有的状态和成员信息,然而他对用户不在可见,因此他的窗口时隐藏的而且当任何地方需要内存的时候,系统会将其杀死。

如果activity暂停或者停止,系统会从内存中抛弃activiy通过要求他结束,或者仅仅杀死这个进程。当他再次展示的时候,他必须是完全重启且存储他之前的状态。

下面的项目展示了activity的重要状态路径。广场的正方形代表了回调方法你能实现,来展示运算当activity在两种状态之间移动。带颜色的主要状态是activity能够进入。

在你监视你的activity的时候,你可能感兴趣的有三个关键的loops。

整个activity的生命周期,从第一次调用onCreate(andorid.os.Bundle)到一个最终的党法调用onDestroy().一个activity将在onCreate()方法中简历所有的全局状态,且释放所有的持有资源在OnDestory()方法中。例如,如果有一个线程在后在运行用来下载数据从网上,他可能创建县城在onCreate()方法中且在onDestory()停止线程。

activity的可视的生命周期在方法onStart()开始,直到响应了方法onStop()。在这期间用户可能看到activity在屏幕上,进过他可能不在最前面且和用不能户进行交互。在这两个方法之间,你的主要字眼需要展示activity给用户。例如,你可以等级旷代接收在onStart()方法中来监视改变,从而影响你的UI且在onStop()方法中注销当用户不看你的展示的时候。onStart和onStop方法可以多次进行调用,当activity对用户可视或者隐藏的时候。

整个activity的生命周期通过下面的Activity方法定义。所有这些方法你可能重写当你的activity改变状态的时候做一些事情。所有的activityes将实现onCreate(andoid.os.Bundle)方法来初始化,很多其他的也实现onPause()方法来确认对数据的改变,此外准备在用户交互的时候停止。你应该常调用你的弗雷到你实现下列的方法的时候。

public class Activity extends ApplicationContext {

protected void onCreate(Bundle savedInstanceState);

protected void onStart();

protected void onRestart();

protected void onResume();

protected void onPause();

protected void onStop();

protected void onDestroy();

}

一个通用的贯穿整个activity生命周期的方法调用如下:

MethodDescriptionKillable?Next

onCreate()Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one.

Always followed byonStart().NoonStart()

onRestart()Called after your activity has been stopped, prior to it being started again.

Always followed byonStart()NoonStart()

onStart()Called when the activity is becoming visible to the user.

Followed byonResume()if the activity comes to the foreground, oronStop()if it becomes hidden.NoonResume()oronStop()

onResume()Called when the activity will start interacting with the user. At this point your activity is at the top of the activity stack, with user input going to it.

Always followed byonPause().NoonPause()

onPause()Called when the system is about to start resuming a previous activity. This is typically used to commit unsaved changes to persistent data, stop animations and other things that may be consuming CPU, etc. Implementations of this method must be very quick because the next activity will not be resumed until this method returns.

Followed by eitheronResume()if the activity returns back to the front, oronStop()if it becomes invisible to the user.YesonResume()or

onStop()

onStop()Called when the activity is no longer visible to the user, because another activity has been resumed and is covering this one. This may happen either because a new activity is being started, an existing one is being brought in front of this one, or this one is being destroyed.

Followed by eitheronRestart()if this activity is coming back to interact with the user, oronDestroy()if this activity is going away.YesonRestart()or

onDestroy()

onDestroy()The final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone calledfinish()on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with theisFinishing()method.

记录下上表中的“Killable”列,对于这些方法标记为能杀死,之后方法返回处理,通过掌握住activity可能被系统杀死在任何时候,在热河一行代码在执行的时候。因为这个原因,你应该使用onPsuse()方法来写任何持久数据来存储。此外,方法onSaveInstanceState(Bundle)被调用在放置activity在后台转台之前,允许你保存任何动态视力状态在你的acti到给定的Bundle中,之后再onCreate(android.os.Bundle)中接收,如果activity需要重新创建。看Process Lifecycle部分的更过信息关于如何将线程绑定到activity的集合。记录下,在onPause()方法中存储持久化数据而不再onSaveInstanceState()方法重要的原因是因为之后他不是生命周期回调的一部分,因此不会在每种情况下调用来描述他的文档。

对于这些方法因为要被杀死,所以没有标记,activity线程不会系统杀死在方法被调用且在其返回值后继续使用。因此,一个activity处于可以被杀死的状态,例如在onPause()方法之后再onResume()方法之前。

六、Configuration Changes

如果设备的配置发生了改变,那么用户用来交互的界面需要更新来匹配数据。因为Activity是主要的用户交互机制,他包含了特定的处理和数据改变。

除非你指定,一个配置改变(例如屏幕的方向,输入设备等)将致使你当前的activity被销毁,通过通常的activity生命周期调用onPause(),onStop(),和onDestroy()方法。如果activity被放置到了最前端或者对用户可视,一旦|onDestroy()在实例中被调用,然后一个新的activity实例将被创建,而不去管saveInstanceState之前由onSaveInstanceState(android.os.Bundle)产生的实例。

在一些特定的例子中你可能想要通过旁路重启你的activity,依据一个或者多个类型的配置改变。这个可以通过手动配置android:configChanges属性实现。就如你说的对于任何类型的配置文件的改变你都要在哪里处理,你将接收到调用你当前activity的onConfigurationChanged(andoird.content.res.Configuration)方法而不是重新启动。如果配置文件改变中包含了任何你不能处理的,然而,activity将重新启动且onConfigrrationChanged()方法被调用。

6.1Starting Activities and Getting Results

方法startActivity()被用来启动一个新的activity,且会将他放到activity栈的最顶部。这会导致一个争论,一个Intent,描述activity的处理。

有时候当activity结束的时候你想要得到一个返回结果。例如,你可以启动一个activity,当你从一个通讯录列表中选择一个用户,当他结束的时候,将选择的用户返回。做这些,你调用startActivityForResult(Intent,int)使用第二个整形参数作为方法的区别。结果将返回通过onActivityResult(int,int,android.content.Intent)方法。

当activity存在,他可以调用setResult(int)方法来返回数据到父**。他必须唱提供一个返回的代码,作为标准的结果RESULT_CANCELED,RESULT_OK或者任何通用值在启动RESULT_FIRST_USER。此外,他可以选择返回一个Intent包含任何你想要附加的数据。所有这些信息都可以出现在父Activity.onActivityResult(),以及它原来提供的整数标识符。

如果一个子activity因某个原因 失败了,父activity将接收到结果代码RESULT_CANCELED

public class MyActivity extends Activity {

...

static final int PICK_CONTACT_REQUEST = 0;

protected boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {

// When the user center presses, let them pick a contact.

startActivityForResult(

new Intent(Intent.ACTION_PICK,

new Uri("content://contacts")),

PICK_CONTACT_REQUEST);

return true;

}

return false;

}

protected void onActivityResult(int requestCode, int resultCode,

Intent data) {

if (requestCode == PICK_CONTACT_REQUEST) {

if (resultCode == RESULT_OK) {

// A contact was picked.  Here we will just display it

// to the user.

startActivity(new Intent(Intent.ACTION_VIEW, data));

}

}

}

}

6.2Saving Persistent State

通常有两种持久化数据状态需要处理,一种分享文档数据(典型的存储在SQLITE的数据,使用content provider)和内在的状态例如用户偏好。

对于内容提供者的数据,我们建议activity使用"edit in place"用户模型。那就是,任何编辑,用户使用高效的即可的而不需要二外的消息步骤。支持这个模型的通常是下面两个原则的简化;

当创建一个新的文件,同时创建他的支持数据库条目或者文件。例如,如果用户选择写一个新的邮件,在输入数据的同时为邮件创建的条目,因此如果他们在此之后进入到任何其他的activity,这个邮件将出现到清单中。

当一个activity的onPause()方法被调用,他将确认返回内容提供者或者任何用户创建的文件。这保证这些改变将被其他相关的,运行的activity看到。你可能想要提交你的数据甚至在你的activity的生命周期的一些关键时刻;例如在开始一个新的activity之前,在结束你自己的activity之前,当用户在不同的输入区域之间转换等场景。

这个模型的设计是为了防止数据丢失当用户是本地的在激活和允许系统安全的杀死一个activity在任何他被暂停的时刻。注意这个应用,用户从你的activity中点击返回不是意味着取消,他代表了离开activity且当前内容保存。在activity中取消编辑必须提供一些其他的机制,例如一个明确的“rever”或者“undo”选项。

看content package 能看到更多的信息。这个是不同的activity之间调用和传播数据的关键地方。

Activity类也提供了API为管理内部的与activity关联的持久状态。这个可以使用,例如,在日历中基础用户的初始化偏好或者用户在网络浏览器中的默认主页。

Activity持久状态使用方法getPreferences(int)来管理,允许你索引和修改一些列名称/值对与activity关联的。为了使用那些分享到多个应用组件的偏好,你可以使用下面的Context.getSharedPreferences()方法去索引偏好的对象存储在一个指定的名称下。(记住,分享设置数据跨越应用时不可能的,对于跨越你需要一个内容提供者)

下面是一个日历摘录activity用来存储用户的偏好视图模型在持久化设置中。

public class CalendarActivity extends Activity {

...

static final int DAY_VIEW_MODE = 0;

static final int WEEK_VIEW_MODE = 1;

private SharedPreferences mPrefs;

private int mCurViewMode;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

SharedPreferences mPrefs = getSharedPreferences();

mCurViewMode = mPrefs.getInt("view_mode" DAY_VIEW_MODE);

}

protected void onPause() {

super.onPause();

SharedPreferences.Editor ed = mPrefs.edit();

ed.putInt("view_mode", mCurViewMode);

ed.commit();

}

}


7、Permissions

开始一个特定的Activity的能力可以强制执行,当他在manifest的<activity> 中声明了tag。通过该动作,其他的应用需要声明响应的<uses-permission>元素在他们自己的manifest中来允许启动activity。

查看Security and Permissions文档来获取关于permission和security更多的信息。

8、Process Lifecycle

安卓系统尝试尽可能长时间的保持应用处理能力,但是最后需要删除旧的进程当内存低的时候。正如在Activity Lifecycle中描述的那样,关于决定哪个进程被移除根据的是当前用户交互的状态信息。通常,根据activity的运行一个进程有四个状态,依据重要性列表如下。系统将杀死相对不重要的进程,在杀死重要的进程之前。

1、最前面的activity(屏幕最上面的activity,用户当前会交互)被认为是最重要的。这个进程被杀死的顺序排在最后,如果他使用了很多的内存。通常此时设备已经达到了警告状态,因此需要为了保持用户界面响应。

2、一个可视的activity(activity能被用户可视,但是不在最前面,例如在最前面后面的对话框)被人没的非常重要的,且除非为了保证最前面的activity运行否则不会被杀死。

3、一个后台运行的activity(不可见的activity,和已经暂停的)不会是决定性的,因此系统可能安全的杀死进程来释放内存给其他的可视进程。如果这个进程需要被杀死,当用户消极返回到activity(使得在屏幕上再次可视),他的onCreate()方法将被调用伴随着saveInstanceState 已经预先应用到onSaveInstanceState(),因此他可以重新启动自身在用户上次使用的相同的状态。

4、一个空的进程没有被任何activity引用或者其他应用组件(例如service或者BroadcastTeceiver类)。当内存变低那些会被系统很快的杀死。对于这个原因,任何在activity之外的后台运算必须在activity中处理。BroadcastReceiver 或者 service 来保证系统知道他需要保持进程。

有时候一个activity可能需要一个长时间的运行运算,独立存在于activity的生命周期。一个例子就是相机应用允许你上传照片到一个网站。上传需要花费很长的时间,且应用允许用户离开应用来处理。为了完成这个,你的activity应该启动一个service用来上传。这允许系统排序权限(认为他比其他不可视的应用要重要)给你的进程在上传的期间,独立于原生activity的暂停,停止和结束。


字段摘要

static intDEFAULT_KEYS_DIALER

Use withsetDefaultKeyMode(int)to launch the dialer during default key handling.

static intDEFAULT_KEYS_DISABLE

Use withsetDefaultKeyMode(int)to turn off default handling of keys.

static intDEFAULT_KEYS_SEARCH_GLOBAL

Use withsetDefaultKeyMode(int)to specify that unhandled keystrokes will start a global search (typically web search, but some platforms may define alternate methods for global search) Seeandroid.app.SearchManagerfor more details.

static intDEFAULT_KEYS_SEARCH_LOCAL

Use withsetDefaultKeyMode(int)to specify that unhandled keystrokes will start an application-defined search.

static intDEFAULT_KEYS_SHORTCUT

Use withsetDefaultKeyMode(int)to execute a menu shortcut in default key handling.

static intRESULT_CANCELED

Standard activity result: operation canceled.

static intRESULT_FIRST_USER

Start of user-defined activity results.

static intRESULT_OK

Standard activity result: operation succeeded.


方法摘要

voidaddContentView(Viewview,ViewGroup.LayoutParamsparams)

Add an additional content view to the activity.

voidcloseContextMenu()

Programmatically closes the most recently opened context menu, if showing.

voidcloseOptionsMenu()

Progammatically closes the options menu.

PendingIntentcreatePendingResult(int requestCode,Intentdata, int flags)

Create a new PendingIntent object which you can hand to others for them to use to send result data back to youronActivityResult(int,

int, android.content.Intent)callback.

voiddismissDialog(int id)

Dismiss a dialog that was previously shown viashowDialog(int).

booleandispatchKeyEvent(KeyEventevent)

Called to process key events.

booleandispatchTouchEvent(MotionEventev)

Called to process touch screen events.

booleandispatchTrackballEvent(MotionEventev)

Called to process trackball events.

ViewfindViewById(int id)

Finds a view that was identified by the id attribute from the XML that was processed inonCreate(android.os.Bundle).

voidfinish()

Call this when your activity is done and should be closed.

voidfinishActivity(int requestCode)

Force finish another activity that you had previously started withstartActivityForResult(android.content.Intent,

int).

voidfinishActivityFromChild(Activitychild, int requestCode)

This is called when a child activity of this one calls its finishActivity().

voidfinishFromChild(Activitychild)

This is called when a child activity of this one calls itsfinish()method.

ApplicationgetApplication()

Return the application that owns this activity.

ComponentNamegetCallingActivity()

Return the name of the activity that invoked this activity.

StringgetCallingPackage()

Return the name of the package that invoked this activity.

intgetChangingConfigurations()

If this activity is being destroyed because it can not handle a configuration parameter being changed (and thus itsonConfigurationChanged(Configuration)method isnotbeing called), then you can use this method to discover the set of changes that have occurred while in the process of being destroyed.

ComponentNamegetComponentName()

Returns complete component name of this activity.

ViewgetCurrentFocus()

CallsWindow.getCurrentFocus()on the Window of this Activity to return the currently focused view.

static longgetInstanceCount()

IntentgetIntent()

Return the intent that started this activity.

ObjectgetLastNonConfigurationInstance()

Retrieve the non-configuration instance data that was previously returned byonRetainNonConfigurationInstance().

LayoutInflatergetLayoutInflater()

Convenience for callingWindow.getLayoutInflater().

StringgetLocalClassName()

Returns class name for this activity with the package prefix removed.

MenuInflatergetMenuInflater()

Returns aMenuInflaterwith this context.

ActivitygetParent()

Return the parent activity if this view is an embedded child.

SharedPreferencesgetPreferences(int mode)

Retrieve aSharedPreferencesobject for accessing preferences that are private to this activity.

intgetRequestedOrientation()

Return the current requested orientation of the activity.

ObjectgetSystemService(Stringname)

Return the handle to a system-level service by name.

intgetTaskId()

Return the identifier of the task this activity is in.

CharSequencegetTitle()

intgetTitleColor()

intgetVolumeControlStream()

Gets the suggested audio stream whose volume should be changed by the harwdare volume controls.

intgetWallpaperDesiredMinimumHeight()

Returns the desired minimum height for the wallpaper.

intgetWallpaperDesiredMinimumWidth()

Returns the desired minimum width for the wallpaper.

WindowgetWindow()

Retrieve the currentWindowfor the activity.

WindowManagergetWindowManager()

Retrieve the window manager for showing custom windows.

booleanhasWindowFocus()

Returns true if this activity'smainwindow currently has window focus.

booleanisChild()

Is this activity embedded inside of another activity?

booleanisFinishing()

Check to see whether this activity is in the process of finishing, either because you calledfinish()on it or someone else has requested that it finished.

booleanisTaskRoot()

Return whether this activity is the root of a task.

voidmanagedCommitUpdates(Cursorc)

已过时。

CursormanagedQuery(Uriuri,String[] projection,Stringselection,StringsortOrder)

Wrapper aroundContentResolver.query(android.net.Uri

, String[], String, String[], String)that gives the resultingCursorto callstartManagingCursor(android.database.Cursor)so that the activity will manage its lifecycle for you.

CursormanagedQuery(Uriuri,String[] projection,Stringselection,String[] selectionArgs,StringsortOrder)

Wrapper aroundContentResolver.query(android.net.Uri

, String[], String, String[], String)that gives the resultingCursorto callstartManagingCursor(android.database.Cursor)so that the activity will manage its lifecycle for you.

booleanmoveTaskToBack(boolean nonRoot)

Move the task containing this activity to the back of the activity stack.

voidonConfigurationChanged(ConfigurationnewConfig)

Called by the system when the device configuration changes while your activity is running.

voidonContentChanged()

This hook is called whenever the content view of the screen changes (due to a call toWindow.setContentVieworWindow.addContentView).

booleanonContextItemSelected(MenuItemitem)

This hook is called whenever an item in a context menu is selected.

voidonContextMenuClosed(Menumenu)

This hook is called whenever the context menu is being closed (either by the user canceling the menu with the back/menu button, or when an item is selected).

voidonCreateContextMenu(ContextMenumenu,Viewv,ContextMenu.ContextMenuInfomenuInfo)

Called when a context menu for theviewis about to be shown.

CharSequenceonCreateDescription()

Generate a new description for this activity.

booleanonCreateOptionsMenu(Menumenu)

Initialize the contents of the Activity's standard options menu.

booleanonCreatePanelMenu(int featureId,Menumenu)

Default implementation ofWindow.Callback.onCreatePanelMenu(int,

android.view.Menu)for activities.

ViewonCreatePanelView(int featureId)

Default implementation ofWindow.Callback.onCreatePanelView(int)for activities.

booleanonCreateThumbnail(BitmapoutBitmap,Canvascanvas)

Generate a new thumbnail for this activity.

ViewonCreateView(Stringname,Contextcontext,AttributeSetattrs)

Stub implementation ofLayoutInflater.Factory.onCreateView(java.lang.String,

android.content.Context, android.util.AttributeSet)used when inflating with the LayoutInflater returned bygetSystemService(java.lang.String).

booleanonKeyDown(int keyCode,KeyEventevent)

Called when a key was pressed down and not handled by any of the views inside of the activity.

booleanonKeyMultiple(int keyCode, int repeatCount,KeyEventevent)

Default implementation ofKeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

booleanonKeyUp(int keyCode,KeyEventevent)

Called when a key was released and not handled by any of the views inside of the activity.

voidonLowMemory()

This is called when the overall system is running low on memory, and would like actively running process to try to tighten their belt.

booleanonMenuItemSelected(int featureId,MenuItemitem)

Default implementation ofWindow.Callback.onMenuItemSelected(int,

android.view.MenuItem)for activities.

booleanonMenuOpened(int featureId,Menumenu)

Called when a panel's menu is opened by the user.

booleanonOptionsItemSelected(MenuItemitem)

This hook is called whenever an item in your options menu is selected.

voidonOptionsMenuClosed(Menumenu)

This hook is called whenever the options menu is being closed (either by the user canceling the menu with the back/menu button, or when an item is selected).

voidonPanelClosed(int featureId,Menumenu)

Default implementation ofWindow.Callback.onPanelClosed(int,

Menu)for activities.

booleanonPrepareOptionsMenu(Menumenu)

Prepare the Screen's standard options menu to be displayed.

booleanonPreparePanel(int featureId,Viewview,Menumenu)

Default implementation ofWindow.Callback.onPreparePanel(int,

android.view.View, android.view.Menu)for activities.

ObjectonRetainNonConfigurationInstance()

Called by the system, as part of destroying an activity due to a configuration change, when it is known that a new instance will immediately be created for the new configuration.

booleanonSearchRequested()

This hook is called when the user signals the desire to start a search.

booleanonTouchEvent(MotionEventevent)

Called when a touch screen event was not handled by any of the views under it.

booleanonTrackballEvent(MotionEventevent)

Called when the trackball was moved and not handled by any of the views inside of the activity.

voidonUserInteraction()

Called whenever a key, touch, or trackball event is dispatched to the activity.

voidonWindowAttributesChanged(WindowManager.LayoutParamsparams)

This is called whenever the current window attributes change.

voidonWindowFocusChanged(boolean hasFocus)

Called when the currentWindowof the activity gains or loses focus.

voidopenContextMenu(Viewview)

Programmatically opens the context menu for a particularview.

voidopenOptionsMenu()

Programmatically opens the options menu.

voidregisterForContextMenu(Viewview)

Registers a context menu to be shown for the given view (multiple views can show the context menu).

voidremoveDialog(int id)

Removes any internal references to a dialog managed by this Activity.

booleanrequestWindowFeature(int featureId)

Enable extended window features.

voidrunOnUiThread(Runnableaction)

Runs the specified action on the UI thread.

voidsetContentView(int layoutResID)

Set the activity content from a layout resource.

voidsetContentView(Viewview)

Set the activity content to an explicit view.

voidsetContentView(Viewview,ViewGroup.LayoutParamsparams)

Set the activity content to an explicit view.

voidsetDefaultKeyMode(int mode)

Select the default key handling for this activity.

voidsetFeatureDrawable(int featureId,Drawabledrawable)

Convenience for callingWindow.setFeatureDrawable(int,

Drawable).

voidsetFeatureDrawableAlpha(int featureId, int alpha)

Convenience for callingWindow.setFeatureDrawableAlpha(int,

int).

voidsetFeatureDrawableResource(int featureId, int resId)

Convenience for callingWindow.setFeatureDrawableResource(int,

int).

voidsetFeatureDrawableUri(int featureId,Uriuri)

Convenience for callingWindow.setFeatureDrawableUri(int,

android.net.Uri).

voidsetIntent(IntentnewIntent)

Change the intent returned bygetIntent().

voidsetPersistent(boolean isPersistent)

Control whether this activity is required to be persistent.

voidsetProgress(int progress)

Sets the progress for the progress bars in the title.

voidsetProgressBarIndeterminate(boolean indeterminate)

Sets whether the horizontal progress bar in the title should be indeterminate (the circular is always indeterminate).

voidsetProgressBarIndeterminateVisibility(boolean visible)

Sets the visibility of the indeterminate progress bar in the title.

voidsetProgressBarVisibility(boolean visible)

Sets the visibility of the progress bar in the title.

voidsetRequestedOrientation(int requestedOrientation)

Change the desired orientation of this activity.

voidsetResult(int resultCode)

Call this to set the result that your activity will return to its caller.

voidsetResult(int resultCode,Intentdata)

Call this to set the result that your activity will return to its caller.

voidsetSecondaryProgress(int secondaryProgress)

Sets the secondary progress for the progress bar in the title.

voidsetTitle(CharSequencetitle)

Change the title associated with this activity.

voidsetTitle(int titleId)

Change the title associated with this activity.

voidsetTitleColor(int textColor)

voidsetVisible(boolean visible)

Control whether this activity's main window is visible.

voidsetVolumeControlStream(int streamType)

Suggests an audio stream whose volume should be changed by the hardware volume controls.

voidshowDialog(int id)

Show a dialog managed by this activity.

voidstartActivity(Intentintent)

Launch a new activity.

voidstartActivityForResult(Intentintent, int requestCode)

Launch an activity for which you would like a result when it finished.

voidstartActivityFromChild(Activitychild,Intentintent, int requestCode)

This is called when a child activity of this one calls itsstartActivity(android.content.Intent)orstartActivityForResult(android.content.Intent,

int)method.

booleanstartActivityIfNeeded(Intentintent, int requestCode)

A special variation to launch an activity only if a new activity instance is needed to handle the given Intent.

voidstartManagingCursor(Cursorc)

This method allows the activity to take care of managing the givenCursor's lifecycle for you based on the activity's lifecycle.

booleanstartNextMatchingActivity(Intentintent)

Special version of starting an activity, for use when you are replacing other activity components.

voidstartSearch(StringinitialQuery, boolean selectInitialQuery,BundleappSearchData, boolean globalSearch)

This hook is called to launch the search UI.

voidstopManagingCursor(Cursorc)

Given a Cursor that was previously given tostartManagingCursor(android.database.Cursor), stop the activity's management of that cursor.

voidtakeKeyEvents(boolean get)

Request that key events come to this activity.

voidunregisterForContextMenu(Viewview)

Prevents a context menu to be shown for the given view.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 156,907评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,546评论 1 289
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,705评论 0 238
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,624评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,940评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,371评论 1 210
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,672评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,396评论 0 195
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,069评论 1 238
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,350评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,876评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,243评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,847评论 3 231
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,004评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,755评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,378评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,266评论 2 259

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 8,534评论 0 23
  • 儿子现在一岁七个月多一点,会叫爸爸妈妈、爷爷奶奶、哥哥姐姐、姥姥、鸟鸟、鸡鹅等等简单词汇,不会表达的时候就拉着你的...
    Mee__阅读 274评论 0 1
  • 一痕伤口,血痂在上 与深深的纹路夹杂在一起 那是岁月和痛的回忆; 那年八岁,他摔了一跤 手上,多了一条伤疤 回家 ...
    骚年木阅读 202评论 0 2