加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20111007194808/http://developer.android.com/reference/android/app/package-summary.html
Since: API Level 1
package

android.app

Contains high-level classes encapsulating the overall Android application model.

An Android application is defined using one or more of Android's four core application components. Two such application components are defined in this package: Activity and Service. The other two components are from the android.content package: BroadcastReceiver and ContentProvider.

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. An activity can start other activities, including activities that live in separate applications.

A Service is an application component that can perform long-running operations in the background without a user interface. For example, a service can handle network transactions, play music, or work with a content provider without the user being aware of the work going on.

The Fragment class is also an important part of an application's design—especially when designing for large screen devices, such as tablets. A fragment defines a distinct part of an activity's behavior, including the associated UI. It has its own lifecycle that is similar to that of the activity and can exist alongside other fragments that are embedded in the activity. While an activity is running, you can add and remove fragments and include each fragment in a back stack that's managed by the activity—allowing the user to navigate backwards through the fragment states, without leaving the activity.

This package also defines application utilities, such as dialogs, notifications, and the action bar.

For information about using some the classes in this package, see the following documents: Activities, Services, Fragments, Using the Action Bar, Creating Dialogs, and Notifying the User.

Interfaces

ActionBar.OnMenuVisibilityListener Listener for receiving events when action bar menus are shown or hidden. 
ActionBar.OnNavigationListener Listener interface for ActionBar navigation events. 
ActionBar.TabListener Callback interface invoked when a tab is focused, unfocused, added, or removed. 
DatePickerDialog.OnDateSetListener The callback used to indicate the user is done filling in the date. 
FragmentBreadCrumbs.OnBreadCrumbClickListener Interface to intercept clicks on the bread crumbs. 
FragmentManager.BackStackEntry Representation of an entry on the fragment back stack, as created with FragmentTransaction.addToBackStack()
FragmentManager.OnBackStackChangedListener Interface to watch for changes to the back stack. 
KeyguardManager.OnKeyguardExitResult Callback passed to exitKeyguardSecurely(KeyguardManager.OnKeyguardExitResult) to notify caller of result. 
LoaderManager.LoaderCallbacks<D> Callback interface for a client to interact with the manager. 
PendingIntent.OnFinished Callback interface for discovering when a send operation has completed. 
SearchManager.OnCancelListener See setOnCancelListener(SearchManager.OnCancelListener) for configuring your activity to monitor search UI state. 
SearchManager.OnDismissListener See setOnDismissListener(SearchManager.OnDismissListener) for configuring your activity to monitor search UI state. 
TimePickerDialog.OnTimeSetListener The callback interface used to indicate the user is done filling in the time (they clicked on the 'Set' button). 

Classes

ActionBar Acts as a replacement for the title bar in Activities. 
ActionBar.LayoutParams Per-child layout information associated with action bar custom views. 
ActionBar.Tab A tab in the action bar. 
Activity An activity is a single, focused thing that the user can do. 
ActivityGroup This class is deprecated. Use the new Fragment and FragmentManager APIs instead; these are also available on older platforms through the Android compatibility package. A screen that contains and runs multiple embedded activities.  
ActivityManager Interact with the overall activities running in the system. 
ActivityManager.MemoryInfo Information you can retrieve about the available memory through getMemoryInfo(ActivityManager.MemoryInfo)
ActivityManager.ProcessErrorStateInfo Information you can retrieve about any processes that are in an error condition. 
ActivityManager.RecentTaskInfo Information you can retrieve about tasks that the user has most recently started or visited. 
ActivityManager.RunningAppProcessInfo Information you can retrieve about a running process. 
ActivityManager.RunningServiceInfo Information you can retrieve about a particular Service that is currently running in the system. 
ActivityManager.RunningTaskInfo Information you can retrieve about a particular task that is currently "running" in the system. 
AlarmManager This class provides access to the system alarm services. 
AlertDialog A subclass of Dialog that can display one, two or three buttons. 
AlertDialog.Builder  
AliasActivity Stub activity that launches another activity (and then finishes itself) based on information in its component's manifest meta-data. 
Application Base class for those who need to maintain global application state. 
DatePickerDialog A simple dialog containing an DatePicker
Dialog Base class for Dialogs. 
DialogFragment A fragment that displays a dialog window, floating on top of its activity's window. 
DownloadManager The download manager is a system service that handles long-running HTTP downloads. 
DownloadManager.Query This class may be used to filter download manager queries. 
DownloadManager.Request This class contains all the information necessary to request a new download. 
ExpandableListActivity An activity that displays an expandable list of items by binding to a data source implementing the ExpandableListAdapter, and exposes event handlers when the user selects an item. 
Fragment A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity
Fragment.SavedState State information that has been retrieved from a fragment instance through FragmentManager.saveFragmentInstanceState
FragmentBreadCrumbs Helper class for showing "bread crumbs" representing the fragment stack in an activity. 
FragmentManager Interface for interacting with Fragment objects inside of an Activity  
FragmentTransaction API for performing a set of Fragment operations. 
Instrumentation Base class for implementing application instrumentation code. 
Instrumentation.ActivityMonitor Information about a particular kind of Intent that is being monitored. 
Instrumentation.ActivityResult Description of a Activity execution result to return to the original activity. 
IntentService IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. 
KeyguardManager Class that can be used to lock and unlock the keyboard. 
KeyguardManager.KeyguardLock This class is deprecated. Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Handle returned by newKeyguardLock(String) that allows you to disable / reenable the keyguard.  
LauncherActivity Displays a list of all activities which can be performed for a given intent. 
LauncherActivity.IconResizer Utility class to resize icons to match default icon size. 
LauncherActivity.ListItem An item in the list  
ListActivity An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. 
ListFragment A fragment that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. 
LoaderManager Interface associated with an Activity or Fragment for managing one or more Loader instances associated with it. 
LocalActivityManager This class is deprecated. Use the new Fragment and FragmentManager APIs instead; these are also available on older platforms through the Android compatibility package.

Helper class for managing multiple running embedded activities in the same process. This class is not normally used directly, but rather created for you as part of the ActivityGroup implementation.

 
NativeActivity Convenience for implementing an activity that will be implemented purely in native code. 
Notification A class that represents how a persistent notification is to be presented to the user using the NotificationManager
Notification.Builder Builder class for Notification objects. 
NotificationManager Class to notify the user of events that happen. This is how you tell the user that something has happened in the background.  
PendingIntent A description of an Intent and target action to perform with it. 
ProgressDialog

A dialog showing a progress indicator and an optional text message or view. 

SearchableInfo Searchability meta-data for an activity. 
SearchManager This class provides access to the system search services. 
Service A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. 
TabActivity This class is deprecated. New applications should use Fragments instead of this class; to continue to run on older devices, you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT.

For apps developing against HONEYCOMB or later, tabs are typically presented in the UI using the new ActionBar.newTab() and related APIs for placing tabs within their action bar area.

A replacement for TabActivity can also be implemented by directly using TabHost. You will need to define a layout that correctly uses a TabHost with a TabWidget as well as an area in which to display your tab content. A typical example would be:

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+android:id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</TabHost>

The implementation needs to take over responsibility for switching the shown content when the user switches between tabs.

import java.util.HashMap;

import com.example.android.supportv4.R;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TabHost;

/**
 * This demonstrates how you can implement switching between the tabs of a
 * TabHost through fragments.  It uses a trick (see the code below) to allow
 * the tabs to switch between fragments instead of simple views.
 */
public class FragmentTabs extends FragmentActivity {
    TabHost mTabHost;
    TabManager mTabManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.fragment_tabs);
        mTabHost = (TabHost)findViewById(android.R.id.tabhost);
        mTabHost.setup();

        mTabManager = new TabManager(this, mTabHost, R.id.realtabcontent);

        mTabManager.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
                FragmentStackSupport.CountingFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
                LoaderCursorSupport.CursorLoaderListFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
                LoaderCustomSupport.AppListFragment.class, null);
        mTabManager.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
                LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);

        if (savedInstanceState != null) {
            mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putString("tab", mTabHost.getCurrentTabTag());
    }

    /**
     * This is a helper class that implements a generic mechanism for
     * associating fragments with the tabs in a tab host.  It relies on a
     * trick.  Normally a tab host has a simple API for supplying a View or
     * Intent that each tab will show.  This is not sufficient for switching
     * between fragments.  So instead we make the content part of the tab host
     * 0dp high (it is not shown) and the TabManager supplies its own dummy
     * view to show as the tab content.  It listens to changes in tabs, and takes
     * care of switch to the correct fragment shown in a separate content area
     * whenever the selected tab changes.
     */
    public static class TabManager implements TabHost.OnTabChangeListener {
        private final FragmentActivity mActivity;
        private final TabHost mTabHost;
        private final int mContainerId;
        private final HashMap<String, TabInfo> mTabs = new HashMap<String, TabInfo>();
        TabInfo mLastTab;

        static final class TabInfo {
            private final String tag;
            private final Class<?> clss;
            private final Bundle args;
            private Fragment fragment;

            TabInfo(String _tag, Class<?> _class, Bundle _args) {
                tag = _tag;
                clss = _class;
                args = _args;
            }
        }

        static class DummyTabFactory implements TabHost.TabContentFactory {
            private final Context mContext;

            public DummyTabFactory(Context context) {
                mContext = context;
            }

            @Override
            public View createTabContent(String tag) {
                View v = new View(mContext);
                v.setMinimumWidth(0);
                v.setMinimumHeight(0);
                return v;
            }
        }

        public TabManager(FragmentActivity activity, TabHost tabHost, int containerId) {
            mActivity = activity;
            mTabHost = tabHost;
            mContainerId = containerId;
            mTabHost.setOnTabChangedListener(this);
        }

        public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
            tabSpec.setContent(new DummyTabFactory(mActivity));
            String tag = tabSpec.getTag();

            TabInfo info = new TabInfo(tag, clss, args);

            // Check to see if we already have a fragment for this tab, probably
            // from a previously saved state.  If so, deactivate it, because our
            // initial state is that a tab isn't shown.
            info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag);
            if (info.fragment != null && !info.fragment.isDetached()) {
                FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
                ft.detach(info.fragment);
                ft.commit();
            }

            mTabs.put(tag, info);
            mTabHost.addTab(tabSpec);
        }

        @Override
        public void onTabChanged(String tabId) {
            TabInfo newTab = mTabs.get(tabId);
            if (mLastTab != newTab) {
                FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
                if (mLastTab != null) {
                    if (mLastTab.fragment != null) {
                        ft.detach(mLastTab.fragment);
                    }
                }
                if (newTab != null) {
                    if (newTab.fragment == null) {
                        newTab.fragment = Fragment.instantiate(mActivity,
                                newTab.clss.getName(), newTab.args);
                        ft.add(mContainerId, newTab.fragment, newTab.tag);
                    } else {
                        ft.attach(newTab.fragment);
                    }
                }

                mLastTab = newTab;
                ft.commit();
                mActivity.getSupportFragmentManager().executePendingTransactions();
            }
        }
    }
}

Also see the Fragment Tabs Pager sample for an example of using the support library's ViewPager to allow the user to swipe the content to switch between tabs.

 
TimePickerDialog A dialog that prompts the user for the time of day using a TimePicker
UiModeManager This class provides access to the system uimode services. 
WallpaperInfo This class is used to specify meta information of a wallpaper service. 
WallpaperManager Provides access to the system wallpaper. 

Exceptions

Fragment.InstantiationException Thrown by instantiate(Context, String, Bundle) when there is an instantiation failure. 
PendingIntent.CanceledException Exception thrown when trying to send through a PendingIntent that has been canceled or is otherwise no longer able to execute the request.