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.jordanfitzgibbon.rfduinohrm.RFduinoService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    if (UUID_RECEIVE.equals(characteristic.getUuid())) {
        final Intent intent = new Intent(action);
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
        sendBroadcast(intent, Manifest.permission.BLUETOOTH);
        Log.w(TAG, "BTLE Data received and broadcasted");

        // Create notification
        Intent notificationIntent = new Intent(RFduinoService.this,
                com.jordanfitzgibbon.rfduinohrm.MainActivity.class);
        notificationIntent.setAction("RFduinoTest_CallToMain");
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(RFduinoService.this, 0, notificationIntent, 0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(RFduinoService.this)
                .setContentTitle("Bluetooth Data").setTicker("New Bluetooth Data Received")
                .setContentText("Data:" + characteristic.getValue() + "\nOr: " + characteristic.getValue())
                //.setContentText("Data:" + HexAsciiHelper.bytesToAsciiMaybe(characteristic.getValue()) + "\nOr: " + HexAsciiHelper.bytesToHex(characteristic.getValue()))
                //.setSmallIcon(R.drawable.ic_launcher)
                //                    .setLargeIcon(
                //                          Bitmap.createScaledBitmap(icon, 128, 128, false))
                .setAutoCancel(true).setContentIntent(pendingIntent);
        mNotificationManager.notify(110, mBuilder.build());
    }//from  w ww  .  ja  v  a  2s. c o  m
}

From source file:org.creativecommons.thelist.activities.StartActivity.java

@Override
protected void onStart() {
    super.onStart();
    Log.v(TAG, "ON START CALLED");
    if (!(mCurrentUser.isTempUser())) {
        Log.v(TAG, "ONSTART: USER IS LOGGED IN");
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);/*from   w w w.ja v a 2s  . co m*/
    } else {
        Log.v(TAG, "ONSTART: USER IS NOT LOGGED IN");
    }

    GoogleAnalytics.getInstance(this).reportActivityStart(this);
    Log.v(TAG, "ON START CALLED  AFTER GA CALLED");
}

From source file:com.oakesville.mythling.MediaPagerActivity.java

protected void goListView(String mode) {
    if (mediaList.getMediaType() == MediaType.recordings
            && getAppSettings().getMediaSettings().getSortType() == SortType.byTitle)
        getAppSettings().clearCache(); // refresh since we're switching from flattened hierarchy

    if (getPath() == null || getPath().isEmpty()) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(MODE_SWITCH, mode);
        intent.putExtra(SEL_ITEM_INDEX, getSelItemIndex());
        startActivity(intent);/*  w ww .j av  a  2  s .co m*/
    } else {
        Uri uri = new Uri.Builder().path(getPath()).build();
        Intent intent = new Intent(Intent.ACTION_VIEW, uri, getApplicationContext(), MediaListActivity.class);
        intent.putExtra(MODE_SWITCH, mode);
        intent.putExtra(SEL_ITEM_INDEX, getSelItemIndex());
        startActivity(intent);
    }
}

From source file:com.lannbox.rfduinotest.RFduinoService.java

private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
    if (UUID_RECEIVE.equals(characteristic.getUuid())) {
        final Intent intent = new Intent(action);
        intent.putExtra(EXTRA_DATA, characteristic.getValue());
        sendBroadcast(intent, Manifest.permission.BLUETOOTH);
        Log.w(TAG, "BTLE Data received and broadcasted");

        // Create notification
        Intent notificationIntent = new Intent(RFduinoService.this, MainActivity.class);
        notificationIntent.setAction("RFduinoTest_CallToMain");
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(RFduinoService.this, 0, notificationIntent, 0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(RFduinoService.this)
                .setContentTitle("Bluetooth Data").setTicker("New Bluetooth Data Received")
                .setContentText("Data:" + HexAsciiHelper.bytesToAsciiMaybe(characteristic.getValue()) + "\nOr: "
                        + HexAsciiHelper.bytesToHex(characteristic.getValue()))
                .setSmallIcon(R.drawable.ic_launcher)
                //                    .setLargeIcon(
                //                          Bitmap.createScaledBitmap(icon, 128, 128, false))
                .setAutoCancel(true).setContentIntent(pendingIntent);
        mNotificationManager.notify(110, mBuilder.build());
    }// w w  w . j  a v  a 2  s.c o  m
}

From source file:com.frostwire.android.gui.NotificationUpdateDemon.java

private PendingIntent createShutdownIntent() {
    return PendingIntent.getActivity(mParentContext, 1,
            new Intent(mParentContext, MainActivity.class).setAction(Constants.ACTION_REQUEST_SHUTDOWN)
                    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK),
            0);/*from www.j  a  va 2  s .c om*/
}

From source file:com.google.samples.apps.sergio.gcm.command.NotificationCommand.java

private void processCommand(Context context, NotificationCommandModel command) {
    // Check format
    if (!"1.0.00".equals(command.format)) {
        LOGW(TAG, "GCM notification command has unrecognized format: " + command.format);
        return;//from   w  w w . j  a  v  a 2s . co m
    }

    // Check app version
    if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) {
        LOGD(TAG, "Command has version range.");
        int minVersion = 0;
        int maxVersion = Integer.MAX_VALUE;
        try {
            if (!TextUtils.isEmpty(command.minVersion)) {
                minVersion = Integer.parseInt(command.minVersion);
            }
            if (!TextUtils.isEmpty(command.maxVersion)) {
                maxVersion = Integer.parseInt(command.maxVersion);
            }
            LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion);
            PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            LOGD(TAG, "My version code: " + pinfo.versionCode);
            if (pinfo.versionCode < minVersion) {
                LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode + " < "
                        + minVersion);
                return;
            }
            if (pinfo.versionCode > maxVersion) {
                LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode + " > "
                        + maxVersion);
                return;
            }
        } catch (NumberFormatException ex) {
            LOGE(TAG,
                    "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion);
            return;
        } catch (Exception ex) {
            LOGE(TAG, "Unexpected problem doing version check.", ex);
            return;
        }
    }

    // Check if we are the right audience
    LOGD(TAG, "Checking audience: " + command.audience);
    if ("remote".equals(command.audience)) {
        if (PrefUtils.isAttendeeAtVenue(context)) {
            LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site");
            return;
        } else {
            LOGD(TAG, "Relevant (attendee is remote).");
        }
    } else if ("local".equals(command.audience)) {
        if (!PrefUtils.isAttendeeAtVenue(context)) {
            LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote.");
            return;
        } else {
            LOGD(TAG, "Relevant (attendee is local).");
        }
    } else if ("all".equals(command.audience)) {
        LOGD(TAG, "Relevant (audience is 'all').");
    } else {
        LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience);
        return;
    }

    // Check if it expired
    Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry);
    if (expiry == null) {
        LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry);
        return;
    } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) {
        LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString());
        return;
    } else {
        LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")");
    }

    // decide the intent that will be fired when the user clicks the notification
    Intent intent;
    if (TextUtils.isEmpty(command.dialogText)) {
        // notification leads directly to the URL, no dialog
        if (TextUtils.isEmpty(command.url)) {
            intent = new Intent(context, MyScheduleActivity.class)
                    .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        } else {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url));
        }
    } else {
        // use a dialog
        intent = new Intent(context, MyScheduleActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE,
                command.dialogTitle == null ? "" : command.dialogTitle);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE,
                command.dialogText == null ? "" : command.dialogText);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES,
                command.dialogYes == null ? "OK" : command.dialogYes);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, command.dialogNo == null ? "" : command.dialogNo);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, command.url == null ? "" : command.url);
    }

    final String title = TextUtils.isEmpty(command.title) ? context.getString(R.string.app_name)
            : command.title;
    final String message = TextUtils.isEmpty(command.message) ? "" : command.message;

    // fire the notification
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.ic_stat_notification).setTicker(command.message)
                    .setContentTitle(title).setContentText(message)
                    //.setColor(context.getResources().getColor(R.color.theme_primary))
                    // Note: setColor() is available in the support lib v21+.
                    // We commented it out because we want the source to compile 
                    // against support lib v20. If you are using support lib
                    // v21 or above on Android L, uncomment this line.
                    .setContentIntent(
                            PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT))
                    .setAutoCancel(true).build());
}

From source file:com.ohnemax.android.glass.doseview.CSDataSort.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {

        // Get an instance of a live card
        mLiveCard = new LiveCard(this, LIVE_CARD_TAG);

        // Inflate a layout into a remote view
        mLiveCardView = new RemoteViews(getPackageName(), R.layout.service_doserate);

        // Set up the live card's action with a pending intent
        // to show a menu when tapped
        Intent menuIntent = new Intent(this, MenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        // Publish the live card
        mLiveCard.publish(PublishMode.REVEAL);

        // Queue the update text runnable
        mHandler.post(mUpdateLiveCardRunnable);
    }/*from w  w w. ja  v a2s .  co m*/
    return START_STICKY;
}

From source file:com.example.ishita.administrativeapp.WardenActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {

        personalData.SaveData(false);/*from  ww w  . jav a  2  s .c  o  m*/
        Intent launch_logout = new Intent(WardenActivity.this, MainActivity.class);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(launch_logout);
        finish();

    } /*else if(id==R.id.password) {
      Intent in = new Intent(getApplicationContext(), ChangePassword.class);
      startActivity(in);
              
      }*/
    return true;
}

From source file:net.digitalfeed.pdroidalternative.intenthandler.PackageChangeHandler.java

private void displayNotification(Context context, NotificationType notificationType, String packageName,
        String label) {//  ww w.  j  a  va  2s.  c  om
    //This pattern is essentially taken from
    //https://developer.android.com/guide/topics/ui/notifiers/notifications.html

    Resources res = context.getResources();

    //TODO: Fix the icon in the notification bar            
    Notification.Builder builder = new Notification.Builder(context).setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(R.drawable.notification_icon);
    //.setLargeIcon(res.getDrawable(R.drawable.allow_icon))

    String appLabel = DBInterface.getInstance(context).getApplicationLabel(packageName);
    Log.d("PDroidAlternative", "new packagename is " + packageName);
    Log.d("PDroidAlternative", "app label is " + appLabel);
    switch (notificationType) {
    case newinstall:
        builder.setContentTitle(appLabel + " " + res.getString(R.string.notification_newinstall_title))
                .setContentText(res.getString(R.string.notification_newinstall_text));
        break;
    case update:
        builder.setContentTitle(appLabel + " " + res.getString(R.string.notification_update_title))
                .setContentText(res.getString(R.string.notification_update_text));
        break;
    }

    Intent packageDetailIntent = new Intent(context, AppDetailActivity.class);
    packageDetailIntent.putExtra(AppDetailActivity.BUNDLE_PACKAGE_NAME, packageName);
    packageDetailIntent.putExtra(AppDetailActivity.BUNDLE_IN_APP, false);
    packageDetailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_CLEAR_TASK);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(AppDetailActivity.class);
    stackBuilder.addNextIntent(packageDetailIntent);

    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    Notification builtNotification = builder.build();
    builtNotification.flags = builtNotification.flags | Notification.FLAG_AUTO_CANCEL
            | Notification.FLAG_NO_CLEAR;

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builtNotification);
}

From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java

private void notifyMatch(long matchId) {
    if (!PrefUtils.shouldShowMatchReminders(this)) {
        return;//  w w  w . j  a v  a  2  s  . c  om
    }

    final ContentResolver cr = getContentResolver();

    Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION,
            SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null);

    if (!c.moveToNext()) {
        return;
    }

    Intent baseIntent = new Intent(this, MatchActivity.class);
    baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent);

    Intent matchIntent = new Intent(this, MatchDetailActivity.class);
    matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId);
    taskBuilder.addNextIntent(matchIntent);

    PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);

    final Resources res = getResources();
    String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs "
            + c.getString(MatchDetailQuery.TEAM_TWO_NAME);

    String contentText;

    long currentTime = TimeUtils.getUTCTime();
    long matchStart = c.getLong(MatchDetailQuery.DATE_TIME);

    int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000;
    if (minutesLeft < 2 && minutesLeft >= 0) {
        minutesLeft = 1;
    }

    if (minutesLeft < 0) {
        contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")";
    } else {
        contentText = "is scheduled to start in " + minutesLeft + " min. ("
                + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")";
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle)
            .setContentText(contentText).setColor(res.getColor(R.color.theme_primary))
            .setTicker(contentTitle + " is about to start.")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true);

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

    nm.notify(NOTIFICATION_ID, notifBuilder.build());
}