Example usage for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

List of usage examples for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.

Prototype

int FLAG_ACTIVITY_RESET_TASK_IF_NEEDED

To view the source code for android.content Intent FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.

Click Source Link

Document

If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.

Usage

From source file:de.mrapp.android.bottomsheet.BottomSheet.java

/**
 * Creates and returns a listener, which allows to start an app, when an item of the bottom
 * sheet has been clicked.//from   ww w  .j  av  a  2  s.  com
 *
 * @param activity
 *         The activity, the bottom sheet belongs to, as an instance of the class {@link
 *         Activity}. The activity may not be null
 * @param intent
 *         The intent, which should be passed to the started app, as an instance of the class
 *         {@link Intent}. The intent may not be null
 * @param resolveInfos
 *         A list, which contains the resolve infos, which correspond to the apps, which are
 *         able to handle the intent, as an instance of the type {@link List} or an empty list,
 *         if no apps are able to handle the intent
 * @return The listener, which has been created, as an instance of the type {@link
 * OnItemClickListener}
 */
private OnItemClickListener createIntentClickListener(@NonNull final Activity activity,
        @NonNull final Intent intent, @NonNull final List<ResolveInfo> resolveInfos) {
    return new OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            ActivityInfo activityInfo = resolveInfos.get(position).activityInfo;
            ComponentName componentName = new ComponentName(activityInfo.applicationInfo.packageName,
                    activityInfo.name);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.setComponent(componentName);
            activity.startActivity(intent);
            dismiss();
        }

    };
}

From source file:com.android.launcher2.Launcher.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isWorkspaceLocked()) {
        return false;
    }//  w  w  w  .  j a v  a2 s .  co m

    super.onCreateOptionsMenu(menu);

    Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
    settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    String helpUrl = getString(R.string.help_url);
    Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
    help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
            .setIcon(android.R.drawable.ic_menu_gallery).setAlphabeticShortcut('W');
    menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps).setIcon(android.R.drawable.ic_menu_manage)
            .setIntent(manageApps).setAlphabeticShortcut('M');
    menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setIntent(settings).setAlphabeticShortcut('P');
    if (!helpUrl.isEmpty()) {
        menu.add(0, MENU_HELP, 0, R.string.menu_help).setIcon(android.R.drawable.ic_menu_help).setIntent(help)
                .setAlphabeticShortcut('H');
    }
    return true;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Cancel search dialog if it is open.//  ww w .j  a  v  a2 s.  c  om
 */
/*
 * void stopSearch() { // Close search dialog SearchManager searchManager =
 * (SearchManager) getSystemService(Context.SEARCH_SERVICE);
 * searchManager.stopSearch(); // Restore search widget to its normal
 * position PersonaSearch searchWidget =
 * mWorkspace.findSearchWidgetOnCurrentScreen(); if (searchWidget != null) {
 * searchWidget.stopSearch(false); } }
 */

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mDesktopLocked && mSavedInstanceState == null)
        return false;

    super.onCreateOptionsMenu(menu);
    menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add).setIcon(android.R.drawable.ic_menu_add)
            .setAlphabeticShortcut('A');
    menu.add(MENU_GROUP_NORMAL, MENU_SEARCH, 0, R.string.menu_search)
            .setIcon(android.R.drawable.ic_search_category_default)
            .setAlphabeticShortcut(SearchManager.MENU_KEY);
    menu.add(MENU_GROUP_NORMAL, MENU_NOTIFICATIONS, 0, R.string.menu_edit)
            .setIcon(android.R.drawable.ic_menu_edit).setAlphabeticShortcut('E');

    final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
    settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    menu.add(MENU_GROUP_NORMAL, MENU_SETTINGS, 0, R.string.menu_settings)
            .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P').setIntent(settings);
    // ADW: add custom settings
    menu.add(MENU_GROUP_NORMAL, MENU_ALMOSTNEXUS, 0, R.string.menu_adw_settings)
            .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('X');

    menu.add(MENU_GROUP_CATALOGUE, MENU_APP_GRP_CONFIG, 0, R.string.AppGroupConfig)
            .setIcon(android.R.drawable.ic_menu_agenda);
    // menu.add(MENU_GROUP_CATALOGUE, MENU_APP_GRP_RENAME, 0,
    // R.string.AppGroupRename)
    // .setIcon(R.drawable.ic_menu_notifications);
    menu.add(MENU_GROUP_CATALOGUE, MENU_APP_SWITCH_GRP, 0, R.string.AppGroupChoose)
            .setIcon(android.R.drawable.ic_menu_manage);
    menu.add(MENU_GROUP_CATALOGUE, MENU_APP_DELETE_GRP, 0, R.string.AppGroupDel)
            .setIcon(android.R.drawable.ic_menu_delete);
    menu.add(MENU_GROUP_NORMAL, MENU_LOCK_DESKTOP, 0, R.string.menu_lock)
            .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('X');
    return true;
}

From source file:com.mobiletin.inputmethod.indic.LatinIME.java

private void launchSettings() {
    mInputLogic.commitTyped(mSettings.getCurrent(), LastComposedWord.NOT_A_SEPARATOR);
    requestHideSelf(0);/* w  w w  .ja va  2 s. c  o m*/
    final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
    if (mainKeyboardView != null) {
        mainKeyboardView.closing();
    }
    final Intent intent = new Intent();
    intent.setClass(LatinIME.this, SettingsActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(SettingsActivity.EXTRA_SHOW_HOME_AS_UP, false);
    startActivity(intent);
}

From source file:com.mobiletin.inputmethod.indic.LatinIME.java

private void showSubtypeSelectorAndSettings() {
    final CharSequence title = getString(R.string.english_ime_input_options);
    // TODO: Should use new string "Select active input modes".
    final CharSequence languageSelectionTitle = getString(R.string.language_selection_title);
    final CharSequence[] items = new CharSequence[] { languageSelectionTitle,
            getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class)) };
    final OnClickListener listener = new OnClickListener() {
        @Override//from   ww w. ja v  a 2  s  .co m
        public void onClick(DialogInterface di, int position) {
            di.dismiss();
            switch (position) {
            case 0:
                final Intent intent = IntentUtils.getInputLanguageSelectionIntent(
                        mRichImm.getInputMethodIdOfThisIme(), Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtra(Intent.EXTRA_TITLE, languageSelectionTitle);
                startActivity(intent);
                break;
            case 1:
                launchSettings();
                break;

            }
        }
    };
    final AlertDialog.Builder builder = new AlertDialog.Builder(
            DialogUtils.getPlatformDialogThemeContext(this));
    builder.setItems(items, listener).setTitle(title);
    final AlertDialog dialog = builder.create();
    dialog.setCancelable(true /* cancelable */);
    dialog.setCanceledOnTouchOutside(true /* cancelable */);
    showOptionDialog(dialog);
}

From source file:com.linkbubble.ui.ContentView.java

private void configureArticleModeButton() {
    ArticleContent articleContent = mWebRenderer.getArticleContent();
    if (articleContent != null) {
        if (mArticleNotificationId == -1 && TextUtils.isEmpty(articleContent.mText) == false
                && Settings.get().getArticleModeOnWearEnabled()) {
            mArticleNotificationId = sNextArticleNotificationId;
            sNextArticleNotificationId++;

            String title = MainApplication.sTitleHashMap != null
                    ? MainApplication.sTitleHashMap.get(articleContent.mUrl.toString())
                    : "Open Bubble";

            Context context = getContext();

            Intent closeTabIntent = new Intent(context, NotificationCloseTabActivity.class);
            closeTabIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            closeTabIntent.putExtra(NotificationCloseTabActivity.EXTRA_DISMISS_NOTIFICATION,
                    mArticleNotificationId);
            PendingIntent closeTabPendingIntent = PendingIntent.getActivity(context, mArticleNotificationId,
                    closeTabIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Intent openTabIntent = new Intent(context, NotificationOpenTabActivity.class);
            openTabIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            openTabIntent.putExtra(NotificationOpenTabActivity.EXTRA_DISMISS_NOTIFICATION,
                    mArticleNotificationId);
            PendingIntent openTabPendingIntent = PendingIntent.getActivity(context,
                    (int) System.currentTimeMillis(), openTabIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            Notification notification = new NotificationCompat.Builder(context)
                    .addAction(R.drawable.ic_action_cancel_white, context.getString(R.string.action_close_tab),
                            closeTabPendingIntent)
                    .setContentTitle(title).setContentText(articleContent.mText)
                    .setSmallIcon(R.drawable.ic_launcher).setGroup(Constant.NOTIFICATION_GROUP_KEY_ARTICLES)
                    .setContentIntent(openTabPendingIntent).build();

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            notificationManager.notify(mArticleNotificationId, notification);
        }/*from   w ww.ja  va2s.co m*/

        if (Settings.get().getArticleModeEnabled()) {
            mArticleModeButton.setVisibility(VISIBLE);
        } else {
            mArticleModeButton.setVisibility(GONE);
        }
    } else {
        mArticleModeButton.setVisibility(GONE);
        if (mArticleRenderer != null) {
            mArticleRenderer.stopLoading();
        }
        cancelWearNotification();
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * ADW: Home binding actions//from ww  w  . j ava  2  s.  c o m
 */
public void fireHomeBinding(int bindingValue, int type) {
    // ADW: switch home button binding user selection
    if (mIsEditMode || mIsWidgetEditMode)
        return;
    switch (bindingValue) {
    case BIND_DEFAULT:
        dismissPreviews();
        if (!mWorkspace.isDefaultScreenShowing()) {
            mWorkspace.moveToDefaultScreen();
        }
        break;
    case BIND_HOME_PREVIEWS:
        if (!mWorkspace.isDefaultScreenShowing()) {
            dismissPreviews();
            mWorkspace.moveToDefaultScreen();
        } else {
            if (!showingPreviews) {
                showPreviews(mHandleView, 0, mWorkspace.mHomeScreens);
            } else {
                dismissPreviews();
            }
        }
        break;
    case BIND_PREVIEWS:
        if (!showingPreviews) {
            showPreviews(mHandleView, 0, mWorkspace.mHomeScreens);
        } else {
            dismissPreviews();
        }
        break;
    case BIND_APPS:
        dismissPreviews();
        if (isAllAppsVisible()) {
            mRAB.setVisibility(View.VISIBLE);
            mLAB.setVisibility(View.VISIBLE);
            mHandleView.updateIcon();
            closeDrawer();
        } else {
            showAllApps(true, null);

        }
        break;
    case BIND_STATUSBAR:
        WindowManager.LayoutParams attrs = getWindow().getAttributes();
        /*
         * if((attrs.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) ==
         * WindowManager.LayoutParams.FLAG_FULLSCREEN){ //go non-full screen
         * fullScreen(false); }else{ //go full screen fullScreen(true); }
         */
        // 290778 commented for Non full screen mode
        fullScreen(false);
        break;
    case BIND_NOTIFICATIONS:
        dismissPreviews();
        showNotifications();
        break;
    case BIND_HOME_NOTIFICATIONS:
        if (!mWorkspace.isDefaultScreenShowing()) {
            dismissPreviews();
            mWorkspace.moveToDefaultScreen();
        } else {
            dismissPreviews();
            showNotifications();
        }
        break;
    case BIND_DOCKBAR:
        dismissPreviews();
        if (showDockBar) {
            if (mDockBar.isOpen()) {
                mDockBar.close();
            } else {
                mDockBar.open();
            }
        }
        break;
    case BIND_APP_LAUNCHER:
        // Launch or bring to front selected app
        // Get PackageName and ClassName of selected App
        String package_name = "";
        String name = "";
        switch (type) {
        case 1:
            package_name = PersonaAlmostNexusSettingsHelper.getHomeBindingAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getHomeBindingAppToLaunchName(this);
            break;
        case 2:
            package_name = PersonaAlmostNexusSettingsHelper.getSwipeUpAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getSwipeUpAppToLaunchName(this);
            break;
        case 3:
            package_name = PersonaAlmostNexusSettingsHelper.getSwipeDownAppToLaunchPackageName(this);
            name = PersonaAlmostNexusSettingsHelper.getSwipeDownAppToLaunchName(this);
            break;
        default:
            break;
        }
        // Create Intent to Launch App
        if (package_name != "" && name != "") {
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            i.setComponent(new ComponentName(package_name, name));
            try {
                startActivity(i);
            } catch (Exception e) {
            }
        }
        break;
    default:
        break;
    }
}