Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

Usage

From source file:co.carlosandresjimenez.android.gotit.RegistrationFragment.java

public void openMainScreen() {

    Intent intent;//from ww w .ja va  2s  . c o m
    if (userTypeSelected.equals(getString(R.string.user_type_follower)))
        intent = new Intent(getActivity(), DataFeedActivity.class);
    else
        intent = new Intent(getActivity(), CheckInListActivity.class);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    this.dismiss();
    getActivity().finish();
}

From source file:com.sender.team.sender.gcm.MyGcmListenerService.java

private void sendNotificationConfirm() {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER")
            .setContentText("? ? ?").setAutoCancel(true)
            .setDefaults(NotificationCompat.DEFAULT_ALL).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.adkdevelopment.earthquakesurvival.ui.DetailFragment.java

/**
 * Sets a share intent on ShareActionProvider
 *///  w  w  w . j a  v  a  2s .  c  o m
private void setShareIntent() {
    if (mShareActionProvider != null) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_TEXT,
                getString(R.string.earthquake_magnitude, mMagnitude) + "\n" + mDate + "\n" + mDescription + "\n"
                        + mDistance + "\n" + getString(R.string.earthquake_depth, mDepth) + "\n" + mLink);
        mShareActionProvider.setShareIntent(intent);
    } else {
        Log.e(TAG, "ShareActionProvider is null");
    }
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void createShortcut(Activity main, String path) {
    File file = new File(path);

    try {//from  www. ja v  a 2 s.co m
        // Create the intent that will handle the shortcut
        Intent shortcutIntent = new Intent(main, Browser.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Browser.EXTRA_SHORTCUT, path);

        // The intent to send to broadcast for register the shortcut intent
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(main, R.drawable.ic_launcher));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        main.sendBroadcast(intent);

        Toast.makeText(main, main.getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(main, main.getString(R.string.error), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName,
        String lookupKey, byte[] bitmapData) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    // Use an implicit intent without a package name set. It is reasonable for a disambiguation
    // dialog to appear when opening QuickContacts from the launcher. Plus, this will be more
    // resistant to future package name changes done to Contacts.
    Intent shortcutIntent = new Intent(ContactsContract.QuickContact.ACTION_QUICK_CONTACT);

    // When starting from the launcher, start in a new, cleared task.
    // CLEAR_WHEN_TASK_RESET cannot reset the root of a task, so we
    // clear the whole thing preemptively here since QuickContactActivity will
    // finish itself when launching other detail activities. We need to use
    // Intent.FLAG_ACTIVITY_NO_ANIMATION since not all versions of launcher will respect
    // the INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION intent extra.
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    // Tell the launcher to not do its animation, because we are doing our own
    shortcutIntent.putExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION, true);

    shortcutIntent.setDataAndType(contactUri, contentType);
    shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_EXCLUDE_MIMES, (String[]) null);

    final Bitmap icon = generateQuickContactIcon(drawable);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    if (TextUtils.isEmpty(displayName)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.missing_name));
    } else {//from   w ww .java 2 s .co  m
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
    }

    mListener.onShortcutIntentCreated(contactUri, intent);
}

From source file:com.example.team04adventure.Controller.OnlineStoryList.java

/**
 * Updates the cached stories with the stories of their online versions.
 * /*from   ww  w  . j  a va 2  s.co  m*/
 * @param view
 *            the current view.
 */
public void sync(View view) {
    StorageManager sm = new StorageManager(this);
    ArrayList<Story> offlines = sm.getAll();
    boolean exists = false;

    if (offlines.isEmpty()) {
        Toast.makeText(getBaseContext(), "You have no stories to sync..", Toast.LENGTH_LONG).show();

    } else {

        Integer tempIndex = Integer.valueOf(-5);
        ArrayList<Story> onlines = new ArrayList<Story>();
        try {
            onlines = new JSONparser().execute(tempIndex).get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (Story s : onlines) {
            for (Story ss : offlines) {
                if (s.getId().equals(ss.getId())) {
                    if (s.getVersion() > ss.getVersion()) {
                        sm.deleteStory(ss);
                        sm.addStory(s);
                        exists = true;
                    }
                }
            }
        }

        if (exists == true) {
            Intent intent = new Intent(OnlineStoryList.this, OnlineStoryList.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }

        else
            Toast.makeText(getBaseContext(), "Everything is up to date.", Toast.LENGTH_LONG).show();
    }
}

From source file:com.artech.android.gcm.GcmIntentService.java

@SuppressLint("InlinedApi")
public void createNotification(String payload, String action, String notificationParameters) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    String appName = getString(R.string.app_name);

    SharedPreferences settings = MyApplication.getInstance().getAppSharedPreferences();
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications //$NON-NLS-1$

    Intent intent = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
    intent.setClassName(this, getPackageName() + ".Main"); //$NON-NLS-1$
    intent.addCategory("android.intent.category.LAUNCHER"); //$NON-NLS-1$

    if (Services.Strings.hasValue(action)) {
        // call main as root of the stack with the action as intent parameter. Use clear_task like GoHome
        if (CompatibilityHelper.isApiLevel(Build.VERSION_CODES.HONEYCOMB))
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        else/* ww w .j  a v  a 2s  . co  m*/
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.putExtra(IntentParameters.NotificationAction, action);
        intent.putExtra(IntentParameters.NotificationParameters, notificationParameters);
        intent.setAction(String.valueOf(Math.random()));
    } else {
        // call main like main application shortcut
        intent.setFlags(0);
        intent.setAction("android.intent.action.MAIN");
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = NotificationHelper.newBuilder(this).setWhen(System.currentTimeMillis())
            .setContentTitle(appName).setContentText(payload).setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(payload))
            .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true).build();

    notificationManager.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32); //$NON-NLS-1$
    editor.commit();
}

From source file:de.uni_koblenz_landau.apow.PatientListActivity.java

/**
 * Called when navigation drawer item is selected.
 * @param position Position//from  w ww. j  av a 2  s .  c  o  m
 */
private void onDrawerItemSelected(int position) {

    if (position == KEY_SETTINGS) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
    }

    if (position == KEY_ABOUT) {
        AboutDialog dialog = new AboutDialog();
        dialog.show(getSupportFragmentManager(), ABOUT_DIALOG_ID);
    }

    if (position == KEY_SIGN_OFF) {

        // Destroy database connection.
        DBHelper.initializeInstance(this);
        DBHelper.getInstance().close();
        DBHelper.getInstance().clear();

        // Delete password from memory.
        getApp().setPassword("");

        // Finish all activities and return to login activity.
        Intent intent = new Intent(this, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        finish();
    }
    mDrawerLayout.closeDrawer(mDrawerOuterLayout);
}

From source file:com.zaparound.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///w ww  . j a  va 2s .c  om
private void sendAcceptNotification(String messagetitle, String messageBody) {
    Intent intent = new Intent(this, LandingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CHATTAB_POSITION", 2);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0)
            .setAutoCancel(true).setContentTitle(messagetitle)
            //.setNumber(++count)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            //.setSubText("\n "+count+" new messages\n")
            .setContentIntent(pendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo))
            .setContentText(messageBody).build();

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:cz.maresmar.sfm.view.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Welcome guide
    if (mPrefs.getBoolean(SettingsContract.FIRST_RUN, SettingsContract.FIRST_RUN_DEFAULT)) {
        Intent firstRunIntent = new Intent(this, WelcomeActivity.class);
        firstRunIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(firstRunIntent);/*from w  w w.  j  a  v a  2 s. co m*/
        finish();
    }
    // Main UI
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Floating button
    mOkFab = findViewById(R.id.main_ok_fab);
    mOkFab.setOnClickListener(view -> {
        AsyncTask.execute(() -> ActionUtils.saveEdits(this, getUserUri()));
        setMenuEditUiShown(false);
        Snackbar.make(view, R.string.main_edit_saved_text, Snackbar.LENGTH_LONG).setAction("Ok", v -> {
        }).show();
    });
    mDiscardFab = findViewById(R.id.main_discard_fab);
    mDiscardFab.setOnClickListener(view -> {
        AsyncTask.execute(() -> ActionUtils.discardEdits(this, getUserUri()));
        setMenuEditUiShown(false);
    });

    // Material Drawer
    // Prepare users section
    mProfiles = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header)
            .addProfiles(ADD_USER_DRAWER_ITEM, MANAGE_USER_DRAWER_ITEM).withOnAccountHeaderListener(this)
            .build();

    // Prepare menu section
    mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(mProfiles)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(R.string.drawer_today).withIcon(R.drawable.ic_today)
                            .withIconTintingEnabled(true).withIdentifier(TODAY_DRAWER_ID),
                    new PrimaryDrawerItem().withName(R.string.drawer_day).withIcon(R.drawable.ic_days)
                            .withIconTintingEnabled(true).withIdentifier(DAY_DRAWER_ID),
                    mPortalDrawerItem = new ExpandableDrawerItem().withName(R.string.drawer_portal)
                            .withIcon(R.drawable.ic_location).withIconTintingEnabled(true)
                            .withIdentifier(PORTAL_EXPANDABLE_DRAWER_ID).withSelectable(false)
                            .withSubItems(ADD_PORTAL_DRAWER_ITEM, MANAGE_PORTAL_DRAWER_ITEM),
                    new PrimaryDrawerItem().withName(R.string.drawer_orders)
                            .withIcon(R.drawable.ic_shopping_cart).withIconTintingEnabled(true)
                            .withIdentifier(ORDERS_DRAWER_ID),
                    new SectionDrawerItem().withName(R.string.drawer_help_and_settings_group),
                    new SecondaryDrawerItem().withName(R.string.drawer_feedback).withIcon(R.drawable.ic_send)
                            .withIconTintingEnabled(true).withIdentifier(FEEDBACK_DRAWER_ID)
                            .withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_settings)
                            .withIcon(R.drawable.ic_settings).withIconTintingEnabled(true)
                            .withIdentifier(SETTINGS_DRAWER_ID).withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_help).withIcon(R.drawable.ic_help)
                            .withIconTintingEnabled(true).withIdentifier(HELP_DRAWER_ID).withSelectable(false),
                    new SecondaryDrawerItem().withName(R.string.drawer_about).withIcon(R.drawable.ic_info)
                            .withIconTintingEnabled(true).withIdentifier(ABOUT_DRAWER_ID).withSelectable(false))
            .withOnDrawerItemClickListener(this).withOnDrawerNavigationListener(this)
            .withActionBarDrawerToggleAnimated(true).withSavedInstance(savedInstanceState).build();

    // Selected user
    if (mSelectedUserId == SettingsContract.LAST_USER_UNKNOWN) {
        mSelectedUserId = mPrefs.getLong(SettingsContract.LAST_USER, SettingsContract.LAST_USER_UNKNOWN);
    }

    // Selected fragment
    if (mSelectedFragmentId == SettingsContract.LAST_FRAGMENT_UNKNOWN) {
        mSelectedFragmentId = mPrefs.getLong(SettingsContract.LAST_FRAGMENT,
                SettingsContract.LAST_FRAGMENT_UNKNOWN);
    }

    String action;
    if (getIntent().getAction() != null) {
        action = getIntent().getAction();
    } else {
        action = Intent.ACTION_MAIN;
    }

    switch (action) {
    case Intent.ACTION_MAIN:
        break;
    case SHOW_ORDERS_ACTION:
        mSelectedFragmentId = ORDER_FRAGMENT_ID;
        break;
    case SHOW_CREDIT_ACTION:
        mDrawer.openDrawer();
        break;
    default:
        throw new UnsupportedOperationException("Unknown action " + action);

    }
    mAppBarLayout = findViewById(R.id.appbar);

    mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getIntArray(R.array.swipeRefreshColors));
    mSwipeRefreshLayout.setOnRefreshListener(this::startRefresh);

    // Load users from db
    getSupportLoaderManager().initLoader(USER_LOADER_ID, null, this);

    LocalBroadcastManager.getInstance(this).registerReceiver(mSyncResultReceiver,
            new IntentFilter(SyncHandler.BROADCAST_SYNC_EVENT));
    LocalBroadcastManager.getInstance(this).registerReceiver(mActionsEventReceiver,
            new IntentFilter(ActionUtils.BROADCAST_ACTION_EVENT));
}