All Downloads are FREE. Search and download functionalities are using the official Maven repository.

android.support.v4.app.ActivityCompat Maven / Gradle / Ivy

Go to download

The Support Package includes static "support libraries" that you can add to your Android application in order to use APIs that are either not available for older platform versions or that offer "utility" APIs that aren't a part of the framework APIs.

The newest version!
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.support.v4.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;

/**
 * Helper for accessing features in {@link android.app.Activity}
 * introduced after API level 4 in a backwards compatible fashion.
 */
public class ActivityCompat {
    /**
     * Invalidate the activity's options menu, if able.
     *
     * 

Before API level 11 (Android 3.0/Honeycomb) the lifecycle of the * options menu was controlled primarily by the user's operation of * the hardware menu key. When the user presses down on the menu key * for the first time the menu was created and prepared by calls * to {@link Activity#onCreateOptionsMenu(android.view.Menu)} and * {@link Activity#onPrepareOptionsMenu(android.view.Menu)} respectively. * Subsequent presses of the menu key kept the existing instance of the * Menu itself and called {@link Activity#onPrepareOptionsMenu(android.view.Menu)} * to give the activity an opportunity to contextually alter the menu * before the menu panel was shown.

* *

In Android 3.0+ the Action Bar forces the options menu to be built early * so that items chosen to show as actions may be displayed when the activity * first becomes visible. The Activity method invalidateOptionsMenu forces * the entire menu to be destroyed and recreated from * {@link Activity#onCreateOptionsMenu(android.view.Menu)}, offering a similar * though heavier-weight opportunity to change the menu's contents. Normally * this functionality is used to support a changing configuration of Fragments.

* *

Applications may use this support helper to signal a significant change in * activity state that should cause the options menu to be rebuilt. If the app * is running on an older platform version that does not support menu invalidation * the app will still receive {@link Activity#onPrepareOptionsMenu(android.view.Menu)} * the next time the user presses the menu key and this method will return false. * If this method returns true the options menu was successfully invalidated.

* * @param activity Invalidate the options menu of this activity * @return true if this operation was supported and it completed; false if it was not available. */ public static boolean invalidateOptionsMenu(Activity activity) { if (Build.VERSION.SDK_INT >= 11) { ActivityCompatHoneycomb.invalidateOptionsMenu(activity); return true; } return false; } /** * Start a set of activities as a synthesized task stack, if able. * *

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for * app navigation using the back key changed. The back key's behavior is local * to the current task and does not capture navigation across different tasks. * Navigating across tasks and easily reaching the previous task is accomplished * through the "recents" UI, accessible through the software-provided Recents key * on the navigation or system bar. On devices with the older hardware button configuration * the recents UI can be accessed with a long press on the Home key.

* *

When crossing from one task stack to another post-Android 3.0, * the application should synthesize a back stack/history for the new task so that * the user may navigate out of the new task and back to the Launcher by repeated * presses of the back key. Back key presses should not navigate across task stacks.

* *

startActivities provides a mechanism for constructing a synthetic task stack of * multiple activities. If the underlying API is not available on the system this method * will return false.

* * @param activity Start activities using this activity as the starting context * @param intents Array of intents defining the activities that will be started. The element * length-1 will correspond to the top activity on the resulting task stack. * @return true if the underlying API was available and the call was successful, false otherwise */ public static boolean startActivities(Activity activity, Intent[] intents) { if (Build.VERSION.SDK_INT >= 11) { ActivityCompatHoneycomb.startActivities(activity, intents); return true; } return false; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy