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:com.ruesga.rview.misc.ActivityHelper.java

public static void openChangeListByFilterActivity(Activity activity, String title, ChangeQuery filter,
        boolean dirty, boolean clearStack) {
    Intent intent = new Intent(activity, ChangeListByFilterActivity.class);
    if (clearStack) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    } else {/*from  w w w.ja  v  a 2  s . c  o m*/
        intent.putExtra(Constants.EXTRA_HAS_PARENT, true);
    }
    intent.putExtra(Constants.EXTRA_TITLE, title);
    intent.putExtra(Constants.EXTRA_FILTER, filter.toString());
    intent.putExtra(Constants.EXTRA_DIRTY, dirty);
    activity.startActivityForResult(intent, LIST_RESULT_CODE);
}

From source file:com.miz.service.MovieLibraryUpdate.java

private void showPostUpdateNotification() {
    // Set up cancel dialog intent
    Intent notificationIntent = new Intent(this, Main.class);
    notificationIntent.putExtra("fromUpdate", true);
    notificationIntent.putExtra("startup", "1");
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    // Setup up notification
    mBuilder = new NotificationCompat.Builder(getApplicationContext());
    mBuilder.setColor(getResources().getColor(R.color.color_primary));
    if (!mStopUpdate) {
        mBuilder.setSmallIcon(R.drawable.ic_done_white_24dp);
        mBuilder.setTicker(getString(R.string.finishedMovieLibraryUpdate));
        mBuilder.setContentTitle(getString(R.string.finishedMovieLibraryUpdate));
        mBuilder.setContentText(getString(R.string.stringJustAdded) + " " + mCount + " "
                + getResources().getQuantityString(R.plurals.moviesInLibrary, mCount));
    } else {/*www .ja v a 2  s .c  om*/
        mBuilder.setSmallIcon(R.drawable.ic_cancel_white_24dp);
        mBuilder.setTicker(getString(R.string.stringUpdateCancelled));
        mBuilder.setContentTitle(getString(R.string.stringUpdateCancelled));
        mBuilder.setContentText(getString(R.string.stringJustAdded) + " " + mCount + " "
                + getResources().getQuantityString(R.plurals.moviesInLibrary, mCount, mCount));
    }
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setAutoCancel(true);

    // Build notification
    Notification updateNotification = mBuilder.build();

    // Show the notification
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (mCount > 0)
        mNotificationManager.notify(POST_UPDATE_NOTIFICATION, updateNotification);
}

From source file:org.wso2.iot.agent.services.operation.OperationManager.java

/**
 * Ring the device./*ww w  .j a v  a  2  s  .  com*/
 *
 * @param operation - Operation object.
 */
public void ringDevice(org.wso2.iot.agent.beans.Operation operation) {
    operation.setStatus(resources.getString(R.string.operation_value_completed));
    resultBuilder.build(operation);
    Intent intent = new Intent(context, AlertActivity.class);
    intent.putExtra(resources.getString(R.string.intent_extra_type),
            resources.getString(R.string.intent_extra_ring));
    intent.putExtra(resources.getString(R.string.intent_extra_message_text),
            resources.getString(R.string.intent_extra_stop_ringing));
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Ringing is activated on the device");
    }
}

From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java

private void syncNotifications(Account account, SyncResult syncResult)
        throws AuthenticationException, IOException {
    final User user = AccountUtils.getUser(getContext(), account.name);
    final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()),
            account, getContext());/*www . j  a va2 s. c o  m*/
    final Gson gson = GsonUtils.getGson();
    final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class);
    if (notifications == null) {
        syncResult.stats.numParseExceptions++;
        LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true);
        return;
    }
    ArrayList<String> fetchedNotCodes = new ArrayList<String>();
    ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>();
    for (Notification not : notifications) {
        final ContentValues values = new ContentValues();
        values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not));
        fetchedNotCodes.add(not.getCode());
        if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values,
                SigarraContract.Notifcations.UPDATE_NOTIFICATION,
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) {
            values.put(SigarraContract.Notifcations.CODE, account.name);
            values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode());
            values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW);
            values.put(SigarraContract.Notifcations.CODE, account.name);
            bulkValues.add(values);
        }

    }
    // inserting the values
    if (bulkValues.size() > 0) {
        getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI,
                bulkValues.toArray(new ContentValues[0]));
        // if the account being synced is the current active accout
        // display notification
        if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) {
            final NotificationManager mNotificationManager = (NotificationManager) getContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext());
            notBuilder.setAutoCancel(true).setOnlyAlertOnce(true)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            if (bulkValues.size() == 1) {
                final Notification notification = gson.fromJson(
                        bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT),
                        Notification.class);
                Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class)
                        .putExtra(NotificationsDescFragment.NOTIFICATION, notification);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage())
                        .setContentTitle(notification.getSubject()).setContentText(notification.getMessage())
                        .setContentIntent(notifyPendingIntent)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())
                                .setBigContentTitle(notification.getSubject())
                                .setSummaryText(notification.getMessage()));
                mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build());
            } else {
                final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size());

                Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class);
                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                // Sets a title for the Inbox style big view
                inboxStyle.setBigContentTitle(notTitle);
                // Moves events into the big view
                for (ContentValues value : bulkValues) {
                    final Notification notification = gson.fromJson(
                            value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class);
                    inboxStyle.addLine(notification.getSubject());
                }
                // Moves the big view style object into the notification
                // object.
                notBuilder.setStyle(inboxStyle);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle)
                        .setContentText("").setContentIntent(notifyPendingIntent);
                mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(),
                        notBuilder.build());
            }

        }
    }
    final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI,
            SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE,
            SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())),
            null);
    try {
        if (syncState.moveToFirst()) {
            if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) {
                // Report that we have checked the notifications
                final ContentValues values = new ContentValues();
                values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis());
                getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values,
                        SigarraContract.LastSync.PROFILE,
                        SigarraContract.LastSync.getLastSyncSelectionArgs(account.name));
            }
        }
    } finally {
        syncState.close();
    }
    ArrayList<String> notToDelete = new ArrayList<String>();
    final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI,
            new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE,
            SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null);
    try {
        if (cursor.moveToFirst()) {
            do {
                final String code = cursor.getString(0);
                if (!fetchedNotCodes.contains(code))
                    notToDelete.add(code);
            } while (cursor.moveToNext());
        } else {
            // no notifications
            getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null);
        }
    } finally {
        cursor.close();
    }
    if (notToDelete.size() > 0)
        getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI,
                SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])),
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name,
                        notToDelete.toArray(new String[0])));
    syncResult.stats.numEntries += notifications.length;
}

From source file:com.ht.app.RestaurantsActivity.java

private void setupShortucts() {

    ShortcutManager shortcutManager = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        shortcutManager = getSystemService(ShortcutManager.class);

        // Contact us
        ShortcutInfo webShortcut = null;
        String contact_us = getString(R.string.txt_contact_us);
        webShortcut = new ShortcutInfo.Builder(this, contact_us).setShortLabel(contact_us)
                .setLongLabel(contact_us).setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setIntent(Utils.getComposeEmailIntent()).setRank(0).build();

        String restaurants = getString(R.string.title_activity_restaurants);
        ShortcutInfo restaurantsShortcut = new ShortcutInfo.Builder(this, restaurants)
                .setShortLabel(restaurants).setLongLabel(restaurants)
                .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setIntent(new Intent(Intent.ACTION_VIEW).setPackage("com.ht")
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).setClass(this, this.getClass()))
                .setRank(2).build();//from  w w w . j a va2  s. c o  m

        String masjid = getString(R.string.title_activity_masjid);
        ShortcutInfo masjidsShortcut = new ShortcutInfo.Builder(this, masjid).setShortLabel(masjid)
                .setLongLabel(masjid).setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                .setIntent(new Intent(Intent.ACTION_VIEW).setPackage("com.ht")
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).setClass(this, MasjidActivity.class))
                .setRank(1).build();
        shortcutManager.setDynamicShortcuts(Arrays.asList(webShortcut, restaurantsShortcut, masjidsShortcut));

    }

}

From source file:azad.hallaji.farzad.com.masirezendegi.PageVirayesh.java

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.END)) {
        drawer.closeDrawer(GravityCompat.END);
    }/* w  w w  .  j  a va 2s.  co  m*/
    Intent intent = new Intent(this, Pagemenu.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(intent);

}

From source file:com.inovex.zabbixmobile.activities.BaseActivity.java

/**
 * If settings have been changed, this method clears all cached data and
 * initiates a fresh login.//w  w  w .  ja va 2 s  . c  o  m
 */
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "onResume");
    ZaxPreferences preferences = ZaxPreferences.getInstance(this);
    this.persistedServerSelection = preferences.getServerSelection();
    this.setServerViews(preferences.getPersistedServerName());
    // if the preferences activity has been closed, we check which
    // preferences have been changed and perform necessary actions
    if (mPreferencesClosed) {
        if (mPreferencesChangedServer && mZabbixDataService != null) {
            mZabbixDataService.performZabbixLogout();
            mZabbixDataService.clearAllData();
            mZabbixDataService.initConnection();
            // update widget because server data has changed
            mServersListAdapter = mZabbixDataService.getServersSelectionAdapter();
            Intent intent = new Intent(getApplicationContext(), WidgetUpdateBroadcastReceiver.class);
            this.sendBroadcast(intent);
            mZabbixDataService.performZabbixLogin(this);
            mPreferencesChangedServer = false;
            restoreServerSelection();
        }
        if (mPreferencesChangedTheme) {
            mPreferencesChangedTheme = false;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                // clear activity history and restart this activity
                Intent restartIntent = getIntent();
                restartIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                finish();
                startActivity(restartIntent);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            } else {
                // as FLAG_ACTIVITY_CLEAR_TASK is not available on Android <
                // version 11, we manually send a broadcast to clear the
                // activity history
                sendBroadcast(new Intent(ACTION_FINISH));
                Intent restartIntent = getIntent();
                restartIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(restartIntent);
            }
        }
        mPreferencesClosed = false;
    } else {
        PubnubPushService.startOrStopPushService(getApplicationContext());
    }
    updateCurrentServerNameView();
}

From source file:info.guardianproject.otr.app.im.app.MessageView.java

/**
 * @param mimeType/*from  ww w. j  a v  a2 s . c om*/
 * @param body
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onClickMediaIcon(String mimeType, Uri mediaUri) {

    if (ChatFileStore.isVfsUri(mediaUri)) {
        if (mimeType.startsWith("image")) {
            Intent intent = new Intent(context, ImageViewActivity.class);
            intent.putExtra(ImageViewActivity.FILENAME, mediaUri.getPath());
            context.startActivity(intent);
            return;
        }
        if (mimeType.startsWith("audio")) {
            new AudioPlayer(getContext(), mediaUri.getPath(), mimeType).play();
            return;
        }
        return;
    } else {

        String body = convertMediaUriToPath(mediaUri);

        if (body == null)
            body = new File(mediaUri.getPath()).getAbsolutePath();

        if (mimeType.startsWith("audio")
                || (body.endsWith("3gp") || body.endsWith("3gpp") || body.endsWith("amr"))) {

            if (mMediaPlayer != null)
                mMediaPlayer.release();

            try {
                mMediaPlayer = new MediaPlayer();
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mMediaPlayer.setDataSource(body);
                mMediaPlayer.prepare();
                mMediaPlayer.start();

                return;
            } catch (IOException e) {
                Log.e(ImApp.LOG_TAG, "error playing audio: " + body, e);
            }

        }

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 11)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        //set a general mime type not specific
        intent.setDataAndType(Uri.parse(body), mimeType);

        Context context = getContext().getApplicationContext();

        if (isIntentAvailable(context, intent)) {
            context.startActivity(intent);
        } else {
            Toast.makeText(getContext(), R.string.there_is_no_viewer_available_for_this_file_format,
                    Toast.LENGTH_LONG).show();
        }
    }
}

From source file:nl.dobots.presence.PresenceDetectionApp.java

private void onNetworkError(String error, boolean present, String location, String additionalInfo) {

    // only trigger notification once as long as the network error is active.
    if (!_networkErrorActive) {
        _networkErrorActive = true;//from ww  w  . ja  va2s  .  c o  m

        if (_settings.isNotificationsEnabled()) {
            Intent contentIntent = new Intent(this, MainActivity.class);
            contentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            PendingIntent piContent = PendingIntent.getActivity(this, 0, contentIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Intent wifiSettingsIntent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);
            PendingIntent piWifiSettings = PendingIntent.getActivity(this, 0, wifiSettingsIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Network Error").setContentText(error)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(error))
                    .addAction(android.R.drawable.ic_menu_manage, "Wifi Settings", piWifiSettings)
                    .setContentIntent(piContent).setDefaults(Notification.DEFAULT_SOUND)
                    .setLights(Color.BLUE, 500, 1000);
            _notificationManager.notify(Config.PRESENCE_NOTIFICATION_ID, builder.build());
            Toast.makeText(this, error, Toast.LENGTH_LONG).show();
        }
    }

    // set logged in as false (because of network error)
    _ask.setLoggedIn(false);

    // store the presence update, will be triggered once network connection is reestablished
    _updateWaiting = true;
    _updateWaitingPresence = present;
    _updateWaitingLocation = location;
    _updateWaitingAdditionalInfo = additionalInfo;

    // just to make sure we don't get stuck
    _updatingPresence = false;
}

From source file:org.iota.wallet.ui.activity.MainActivity.java

private void updateDynamicShortcuts() {
    ShortcutManager shortcutManager;//from ww  w  .  j  a v a  2s  .c  o m

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {

        Intent intentGenerateQrCode = new Intent(this, MainActivity.class);
        intentGenerateQrCode.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        intentGenerateQrCode.setAction(Constants.ACTION_GENERATE_QR_CODE);

        ShortcutInfo shortcutGenerateQrCode = new ShortcutInfo.Builder(this, SHORTCUT_ID_GENERATE_QR_CODE)
                .setShortLabel(getString(R.string.shortcut_generate_qr_code))
                .setLongLabel(getString(R.string.shortcut_generate_qr_code))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_qr))
                .setIntent(intentGenerateQrCode).build();

        Intent intentTransferIotas = new Intent(this, MainActivity.class);
        intentTransferIotas.setFlags((Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        intentTransferIotas.setAction(Constants.ACTION_SEND_TRANSFER);

        ShortcutInfo shortcutTransferIotas = new ShortcutInfo.Builder(this, SHORTCUT_ID_SEND_TRANSFER)
                .setShortLabel(getString(R.string.shortcut_send_transfer))
                .setLongLabel(getString(R.string.shortcut_send_transfer))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut_transaction))
                .setIntent(intentTransferIotas).build();

        shortcutManager = getSystemService(ShortcutManager.class);

        if (shortcutManager != null) {
            if (IOTA.seed != null) {
                shortcutManager
                        .setDynamicShortcuts(Arrays.asList(shortcutGenerateQrCode, shortcutTransferIotas));
                shortcutManager.enableShortcuts(
                        Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
            } else {
                // remove shortcuts if Iota.seed.isEmpty()
                shortcutManager.disableShortcuts(
                        Arrays.asList(SHORTCUT_ID_GENERATE_QR_CODE, SHORTCUT_ID_SEND_TRANSFER));
                shortcutManager.removeAllDynamicShortcuts();
            }
        }
    }
}