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:info.guardianproject.otr.app.im.app.AccountListActivity.java

private void doHardShutdown() {

    for (IImConnection conn : mApp.getActiveConnections()) {
        try {//from w w  w .  j a va 2  s  .c o m
            conn.logout();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    Intent intent = new Intent(getApplicationContext(), WelcomeActivity.class);
    // Request lock
    intent.putExtra("doLock", true);
    // Clear the backstack
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();
}

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

private void sendChatNotification(ChattingReceiveData m) {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.putExtra(ChattingActivity.EXTRA_USER, m.getSender());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    if (!TextUtils.isEmpty(m.getSender().getFileUrl())) {
        Bitmap bitmap = null;//from   w  w w .j a va 2  s . com
        try {
            bitmap = Glide.with(getApplicationContext()).load(m.getSender().getFileUrl()).asBitmap()
                    .into(-1, -1).get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        if (bitmap != null) {
            notificationBuilder.setLargeIcon(bitmap);
        }
    } else {
        notificationBuilder
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.default_profile));
    }
    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER")
            .setContentTitle(m.getSender().getName()).setNumber(m.getData().size()).setAutoCancel(true)
            .setDefaults(NotificationCompat.DEFAULT_ALL).setContentIntent(pendingIntent);
    if (!TextUtils.isEmpty(m.getData().get(m.getData().size() - 1).getMessage())) {
        notificationBuilder.setContentText(m.getData().get(m.getData().size() - 1).getMessage());
    } else {
        notificationBuilder.setContentText("");
    }

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

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

From source file:com.waz.zclient.pages.main.profile.ZetaPreferencesActivity.java

@Override
public void onLogout() {
    Timber.i("onLogout");
    getStoreFactory().reset();//from  ww  w . ja  v a 2s. c o  m
    getControllerFactory().getPickUserController().hideUserProfile();
    getControllerFactory().getUserPreferencesController().reset();
    getStoreFactory().getConversationStore().onLogout();
    getControllerFactory().getNavigationController().resetPagerPositionToDefault();

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}

From source file:com.nutsuser.ridersdomain.activities.LiveforDream.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent intent = new Intent(LiveforDream.this, MainScreenActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("MainScreenResponse", "OPEN");
        startActivity(intent);/*from  w  w  w. j  a va2s .com*/
        finish();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.administrator.myapplication2._3_HB._3_MainActivity.java

@Override
public void onBackPressed() {

    ExampleFragment frg = (ExampleFragment) mSectionsPagerAdapter.getItem(FragmentAdapter.FRAGMENT_POS_EXAMPLE);
    frg.stopThread();/*from   w  ww  .j a  v a2s .c  o m*/
    //Set Class to Top of App and no history
    Intent launchNextActivity;
    launchNextActivity = new Intent(this, Main.class);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(launchNextActivity);
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_SingUp.java

public void backButton() {
    Intent slideactivity = new Intent(Activity_SingUp.this, Activity_Main.class);
    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    Bundle bndlanimation = ActivityOptions
            .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright).toBundle();
    startActivity(slideactivity, bndlanimation);
}

From source file:bander.notepad.Notepad.java

/**
 * Sets the theme for AppCompat. There is really no dark theme at the moment, it is mainly for
 * the Toolbar Color Chooser./*www.jav a 2 s.c  o  m*/
 *
 * @param activity ActionBarActivity acting as a Context
 * @param classType Launch a new activity.
 */
public static void setAppCompatThemeFromPreferences(ActionBarActivity activity, String classType) {
    SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(activity);
    if (mSettings.getString("themeType", "0").equals("0")) {
        final int abc = mSettings.getInt("actionBarColor", 0);

        /**
         * In case you are wondering, the random numbers are the 500 colors that show up with
         * black text from here:
         * {@link http://www.google.com/design/spec/style/color.html}
         * The black text means that I have to use a light theme.
         */
        if (abc >= 11 && abc <= 15 || abc == 18) {
            mSettings.edit().putBoolean("darkAppCompatTheme", false).apply();
        } else {
            mSettings.edit().putBoolean("darkAppCompatTheme", true).apply();
        }
    } else {
        /**
         * Somehow, we ended up with the wrong theme, so let's launch the right activity.
         */
        switch (classType) {
        case "Prefs": {
            Intent intent = new Intent();
            intent.setClass(activity, PrefsActivity.class);
            activity.startActivity(intent);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            new PrefsActivityAppCompat().finish();
            break;
        }
        case "Edit": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteEdit.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteEditAppCompat().finish();
            break;
        }
        case "NoteList": {
            Intent intent = new Intent();
            intent.setClass(activity, NoteList.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            new NoteListAppCompat().finish();
            break;
        }
        default: {
            Intent intent = new Intent();
            intent.setClass(activity, Notepad.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
            break;
        }
        }
    }
}

From source file:com.meetingcpp.sched.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;// w w  w  . j av a 2  s .c o  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 (SettingsUtils.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 (!SettingsUtils.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_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.prey.events.factories.EventFactory.java

public static void notification(Context ctx) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (PreyConfig.getPreyConfig(ctx).isThisDeviceAlreadyRegisteredWithPrey(false)) {
            PreyConfig.getPreyConfig(ctx).setCanAccessCamara(PreyPermission.canAccessCamera(ctx));
            PreyConfig.getPreyConfig(ctx)
                    .setCanAccessCoarseLocation(PreyPermission.canAccessCoarseLocation(ctx));
            PreyConfig.getPreyConfig(ctx).setCanAccessFineLocation(PreyPermission.canAccessFineLocation(ctx));
            PreyConfig.getPreyConfig(ctx)
                    .setCanAccessReadPhoneState(PreyPermission.canAccessReadPhoneState(ctx));
            if (!PreyPermission.canAccessCamera(ctx) || !PreyPermission.canAccessCoarseLocation(ctx)
                    || !PreyPermission.canAccessFineLocation(ctx)
                    || !PreyPermission.canAccessReadPhoneState(ctx)) {
                Intent intent3 = new Intent(ctx, CheckPasswordActivity.class);
                intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent3,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationManager nManager = (NotificationManager) ctx
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                android.support.v4.app.NotificationCompat.Builder mBuilder = new android.support.v4.app.NotificationCompat.Builder(
                        ctx).setSmallIcon(R.drawable.logo)
                                .setContentTitle(
                                        ctx.getResources().getString(R.string.warning_notification_title))
                                .setContentText(
                                        ctx.getResources().getString(R.string.warning_notification_body));
                mBuilder.setContentIntent(pendingIntent);
                mBuilder.setAutoCancel(true);
                nManager.notify(PreyConfig.TAG, PreyConfig.NOTIFY_ANDROID_6, mBuilder.build());
            }/*from w  w w .ja  v  a 2s . co m*/
        }
    }
}

From source file:com.google.samples.apps.iosched.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 ava2 s .c om
    }

    // 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 (SettingsUtils.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 (!SettingsUtils.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_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());
}