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:cz.maresmar.sfm.view.MainActivity.java

/**
 * Returns {@link PendingIntent} that can start this activity with last used fragment
 *
 * @param context Some valid context//from   w w w .  j  a va2 s  .c  o m
 * @return PendingIntent that starts activity
 */
public static PendingIntent getDefaultIntent(Context context) {
    Intent intent = new Intent(context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    return PendingIntent.getActivity(context, 0, intent, 0);
}

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

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

        personalData.SaveData(false);//from   ww w. ja  v  a  2s .c  o m
        Intent launch_logout = new Intent(WatchmanActivity.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:org.creativecommons.thelist.activities.RandomActivity.java

private void updateView() {
    mProgressBar.setVisibility(View.INVISIBLE);
    if (mRandomItemData == null) {
        //TODO: better error message
        mMessageHelper.showDialog(mContext, "Oops", "No data found. Please try again.");
    } else {//from   w  ww. j a v a  2 s.  co m
        try {
            if (itemPositionCount == mRandomItemData.length()) {
                //If you run out of items, just go to MainActivity
                if (mCurrentUser.isTempUser()) {
                    saveTempUserItems();
                }

                //Clear ItemList
                mItemList.clear();

                Intent intent = new Intent(RandomActivity.this, DrawerActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);

            } else {
                mListItemData = mRandomItemData.getJSONObject(itemPositionCount);
                mItemID = mListItemData.getString(ApiConstants.ITEM_ID);
                mItemName = mListItemData.getString(ApiConstants.ITEM_NAME);
                mMakerName = mListItemData.getString(ApiConstants.MAKER_NAME);
                mCategoryID = mListItemData.getString(ApiConstants.ITEM_CATEGORY);

                //Update UI
                switch (Integer.valueOf(mCategoryID)) {
                case ApiConstants.PEOPLE:

                    setButtonTheme(mYesButton, R.drawable.check_default_orange, R.drawable.check_pressed_orange,
                            R.drawable.check_pressed_orange);
                    setButtonTheme(mNoButton, R.drawable.x_default_orange, R.drawable.x_pressed_orange,
                            R.drawable.x_pressed_orange);

                    mTextView.setTextColor(getResources().getColor(R.color.people_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.people_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.people_500));
                    break;

                case ApiConstants.PLACES:
                    setButtonTheme(mYesButton, R.drawable.check_default_red, R.drawable.check_pressed_red,
                            R.drawable.check_pressed_red);
                    setButtonTheme(mNoButton, R.drawable.x_default_red, R.drawable.x_pressed_red,
                            R.drawable.x_pressed_red);

                    mTextView.setTextColor(getResources().getColor(R.color.places_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.places_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.places_500));
                    break;

                case ApiConstants.CLOTHING:
                    setButtonTheme(mYesButton, R.drawable.check_default_indigo, R.drawable.check_pressed_indigo,
                            R.drawable.check_pressed_indigo);
                    setButtonTheme(mNoButton, R.drawable.x_default_indigo, R.drawable.x_pressed_indigo,
                            R.drawable.x_pressed_indigo);

                    mTextView.setTextColor(getResources().getColor(R.color.clothing_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.clothing_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.clothing_500));
                    break;

                case ApiConstants.NATURE:
                    setButtonTheme(mYesButton, R.drawable.check_default_green, R.drawable.check_pressed_green,
                            R.drawable.check_pressed_green);
                    setButtonTheme(mNoButton, R.drawable.x_default_green, R.drawable.x_pressed_green,
                            R.drawable.x_pressed_green);

                    mTextView.setTextColor(getResources().getColor(R.color.nature_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.nature_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.nature_500));
                    break;

                case ApiConstants.FOOD:
                    setButtonTheme(mYesButton, R.drawable.check_default_blue, R.drawable.check_pressed_blue,
                            R.drawable.check_pressed_blue);
                    setButtonTheme(mNoButton, R.drawable.x_default_blue, R.drawable.x_pressed_blue,
                            R.drawable.x_pressed_blue);

                    mTextView.setTextColor(getResources().getColor(R.color.food_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.food_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.food_500));
                    break;

                case ApiConstants.OBJECTS:
                    setButtonTheme(mYesButton, R.drawable.check_default_pink, R.drawable.check_pressed_pink,
                            R.drawable.check_pressed_pink);
                    setButtonTheme(mNoButton, R.drawable.x_default_pink, R.drawable.x_pressed_pink,
                            R.drawable.x_pressed_pink);

                    mTextView.setTextColor(getResources().getColor(R.color.objects_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.objects_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.objects_500));
                    break;
                default:
                    setButtonTheme(mYesButton, R.drawable.check_default_default,
                            R.drawable.check_pressed_default, R.drawable.check_pressed_default);
                    setButtonTheme(mNoButton, R.drawable.x_default_default, R.drawable.x_pressed_default,
                            R.drawable.x_pressed_default);

                    mTextView.setTextColor(getResources().getColor(R.color.default_100));
                    mDoneButton.setTextColor(getResources().getColor(R.color.default_100));
                    mBackground.setBackgroundColor(getResources().getColor(R.color.default_500));
                    break;
                }

                mTextView.setText(mMakerName + " needs a picture of " + mItemName);
                mYesButton.setVisibility(View.VISIBLE);
                mNoButton.setVisibility(View.VISIBLE);

                itemPositionCount++;
            }
        } catch (JSONException e) {
            Log.e(TAG, e.getMessage());
        }
    }
}

From source file:com.learnit.LearnIt.data_types.NotificationBuilder.java

private static boolean CreateNotifications(ArrayList<ArticleWordId> randWords, Context context,
        int wayToLearn) {
    ArrayList<Intent> intents = new ArrayList<Intent>();
    ArrayList<Integer> ids = new ArrayList<Integer>();
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> articles = new ArrayList<String>();
    ArrayList<String> translations = new ArrayList<String>();
    ArrayList<String> prefixes = new ArrayList<String>();
    ArrayList<Integer> directionsOfTrans = new ArrayList<Integer>();
    ArrayList<Integer> typesOfHomeworks = new ArrayList<Integer>();
    ArrayList<Class> classes = new ArrayList<Class>();
    for (ArticleWordId struct : randWords) {
        int homeworkActivityType = getHomeworkType(wayToLearn, struct.article);
        int directionOfTranslation = getDirectionOfTranslation(context, sp, homeworkActivityType);
        ids.add(struct.id + idModificator);
        words.add(struct.word);/*from   ww  w.j  a v a  2 s. c  o  m*/
        articles.add(struct.article);
        translations.add(struct.translation);
        prefixes.add(struct.prefix);
        intents.add(getIntentFromHomeworkType(context, homeworkActivityType));
        typesOfHomeworks.add(homeworkActivityType);
        classes.add(getStackTypeFromHomeworkType(homeworkActivityType));
        directionsOfTrans.add(directionOfTranslation);
    }
    for (int i = 0; i < intents.size(); ++i) {
        Intent intent = intents.get(i);
        intent.putExtra(IDS_TAG, ids);
        intent.putExtra(WORDS_TAG, words);
        intent.putExtra(TRANSLATIONS_TAG, translations);
        intent.putExtra(ARTICLES_TAG, articles);
        intent.putExtra(PREFIXES_TAG, prefixes);
        intent.putExtra(DIRECTIONS_OF_TRANS_TAG, directionsOfTrans);
        intent.putExtra(HOMEWORK_TYPE_TAG, typesOfHomeworks);
        intent.putExtra(CURRENT_NOTIFICATION_INDEX, i);
        intent.setAction(ids.get(i) + " " + words.get(i) + " " + System.currentTimeMillis());
        NotificationCompat.Builder mBuilder;
        mBuilder = getBuilder(context, directionsOfTrans.get(i), randWords.get(i));
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        stackBuilder.addParentStack(classes.get(i));
        stackBuilder.addNextIntent(intent);
        PendingIntent pendInt = PendingIntent.getActivity(context, ids.get(i), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        if (null != mBuilder) {
            mBuilder.setSmallIcon(Utils.getIconForWordNumber(i + 1));
            mBuilder.setContentIntent(pendInt);
            mBuilder.setPriority(Notification.PRIORITY_MAX);
            mBuilder.setOngoing(true);
            NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(ids.get(i), mBuilder.build());
            currentIds = currentIds + ids.get(i) + " ";
        } else
            return false;
    }
    return true;
}

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

@Override
public void onUserSignedIn(Bundle userData) {
    Intent intent = new Intent(StartActivity.this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);/* w  w w  . j  a v  a  2  s  . co m*/
}

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

@Override
public void onBackPressed() {
    if (EpgActivity.class.getName().equals(backTo) || FireTvEpgActivity.class.getName().equals(backTo)) {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);/*from   w w w. j  a v  a2  s  . c  o m*/
    } else if (modeSwitch) {
        modeSwitch = false;
        Intent intent = new Intent(this, MediaPagerActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    } else {
        super.onBackPressed();
    }
}

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

/**
 * Returns {@link PendingIntent} that can start this activity with {@link OrderFragment}
 *
 * @param context Some valid context/*from  www  . j  av a  2s  .  c om*/
 * @return PendingIntent that starts activity
 */
public static PendingIntent getShowOrdersIntent(Context context) {
    Intent intent = new Intent(context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.setAction(SHOW_ORDERS_ACTION);
    return PendingIntent.getActivity(context, 0, intent, 0);
}

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

@Override
public void onUserSignedUp(Bundle userData) {
    Intent intent = new Intent(StartActivity.this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);/*from  w w  w  . j a  v a2 s  .  co m*/
}

From source file:com.daskiworks.ghwatch.ActivityBase.java

protected boolean checkUserLoggedIn() {
    if (AuthenticationManager.getInstance().loadCurrentUser(this) == null) {
        Intent intent = new Intent(this, StartActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        this.startActivity(intent);
        return false;
    }/*from   w  w w  . j  av  a2s .c o m*/
    return true;
}

From source file:cn.com.incardata.autobon_shops.CooperativeThreeActivity.java

public void showTipsDialog() {
    final CheckTipsDialog dialog = new CheckTipsDialog(this, R.style.TipsDialog);
    dialog.setOnPositiveListener(new View.OnClickListener() {
        @Override/*from w  w w .  j a v a  2s.  c  o m*/
        public void onClick(View view) {
            dialog.dismiss();
            //TODO ?
        }
    });
    dialog.show();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            Intent intent = new Intent(getContext(), LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        }
    });
}