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.macmoim.pang.MainActivity.java

private void GotoStartActivity() {
    Intent intent = new Intent(this, StartActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);//from   w w  w  .j  a va 2 s  . c o m
    mDrawerLayout.closeDrawers();
    //                if (mCf != null) {
    //                    mCf.menuClose(true);
    //                }
}

From source file:com.google.android.gms.samples.wallet.FullWalletConfirmationButtonFragment.java

/**
 * Here the client should connect to their server, process the credit card/instrument
 * and get back a status indicating whether charging the card was successful or not
 *//*from ww  w. j a  v  a  2 s . c o  m*/
private void fetchTransactionStatus(FullWallet fullWallet) {
    if (mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }
    // Send back details such as fullWallet.getProxyCard() and fullWallet.getBillingAddress()
    // and get back success or failure
    // The following code assumes a successful response and calls notifyTransactionStatus
    Wallet.Payments.notifyTransactionStatus(mGoogleApiClient, WalletUtil.createNotifyTransactionStatusRequest(
            fullWallet.getGoogleTransactionId(), NotifyTransactionStatusRequest.Status.SUCCESS));

    Intent intent = new Intent(getActivity(), OrderCompleteActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Constants.EXTRA_FULL_WALLET, fullWallet);
    startActivity(intent);
}

From source file:com.zira.profile.GetProfile.java

@Override
public void processFinish(String output, String methodName) {
    // TODO Auto-generated method stub
    ZiraParser parser = new ZiraParser();
    Log.e("logout", output);
    if (methodName.equals("Logout")) {

        String result = parser.Logout(output);
        if (result.equals("0")) {
            e.putString("FBAccessToken", "");
            e.putLong("FBAccessExpires", 0);
            e.putString("Login", "");
            e.putString("Userid", "");
            e.putString("mode", "");
            e.putString("_Login", "");
            e.clear();/*  ww w . j av a2 s  . c  o m*/
            e.commit();

            Intent mIntent = new Intent(GetProfile.this, LoginActivity.class);
            SingleTon.getInstance().setEdited(true);
            mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(mIntent);
        } else {
            Util.alertMessage(GetProfile.this, result);
        }
    }
}

From source file:cn.ucai.superwechat.ui.SettingsActivity.java

void logout() {
    final ProgressDialog pd = new ProgressDialog(this);
    String st = getResources().getString(R.string.Are_logged_out);
    pd.setMessage(st);//from   ww  w  .j a  va 2 s .c  om
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    SuperWeChatHelper.getInstance().logout(false, new EMCallBack() {

        @Override
        public void onSuccess() {
            runOnUiThread(new Runnable() {
                public void run() {
                    pd.dismiss();
                    //                show login screen
                    //               ExitAppUtils.getInstance().exit();
                    finish();
                    startActivity(new Intent(SettingsActivity.this, LoginActivity.class)
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK));

                }
            });
        }

        @Override
        public void onProgress(int progress, String status) {

        }

        @Override
        public void onError(int code, String message) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    pd.dismiss();
                    Toast.makeText(SettingsActivity.this, "unbind devicetokens failed", Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
    });
}

From source file:com.hrs.filltheform.dialog.FillTheFormDialog.java

@Override
public void onPropertyChanged(String property) {
    switch (property) {
    case FillTheFormDialogModel.PROPERTY_DIALOG_VISIBILITY:
        if (model.isDialogVisible()) {
            windowManager.addView(dialogView, dialogParams);
        } else {//from   www.ja va 2  s. com
            removeDialogView();
        }
        break;
    case FillTheFormDialogModel.PROPERTY_EXPAND_ICON:
        if (model.isExpandIconVisible()) {
            expandIcon.setVisibility(View.VISIBLE);
        } else {
            expandIcon.setVisibility(View.GONE);
        }
        break;
    case FillTheFormDialogModel.PROPERTY_EXPAND_ICON_FAST_MODE:
        if (model.isFastModeEnabled()) {
            expandIconFastMode.setVisibility(View.VISIBLE);
        } else {
            expandIconFastMode.setVisibility(View.GONE);
        }
        break;
    case FillTheFormDialogModel.PROPERTY_CONFIGURATION_ITEMS_LIST:
        configurationItemsAdapter.notifyDataSetChanged();
        configurationItemsView.scrollToPosition(0);
        break;
    case FillTheFormDialogModel.PROPERTY_ACTION_SET_TEXT:
        fillTheSelectedNodeWithData(model.getSelectedConfigItemValue());
        configurationItemsAdapter.notifyDataSetChanged();
        break;
    case FillTheFormDialogModel.PROPERTY_ACTION_PASTE:
        pasteTheData(model.getSelectedConfigItemValue());
        configurationItemsAdapter.notifyDataSetChanged();
        break;
    case FillTheFormDialogModel.PROPERTY_DIALOG_EXPANDED:
        if (model.isDialogExpanded()) {
            dialogMenu.setVisibility(View.VISIBLE);
            dialogParams.width = model.getExpandedDialogWidth();
            dialogParams.height = model.getExpandedDialogHeight();
        } else {
            dialogMenu.setVisibility(View.GONE);
            dialogParams.width = model.getNormalDialogWidth();
            dialogParams.height = model.getNormalDialogHeight();
        }
        updateDialogViewSize();
        break;
    case FillTheFormDialogModel.PROPERTY_DIALOG_INITIAL_POSITION:
        if (!model.isDialogExpanded()) {
            setUpInitialDialogPosition();
        }
        break;
    case FillTheFormDialogModel.PROPERTY_DIALOG_POSITION:
        dialogParams.x = model.getDialogPositionX();
        dialogParams.y = model.getDialogPositionY();
        windowManager.updateViewLayout(dialogView, dialogParams);
        break;
    case FillTheFormDialogModel.PROPERTY_OPEN_FILL_THE_FORM_APP_BUTTON:
        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(launchIntent);
        break;
    case FillTheFormDialogModel.PROPERTY_CLEAR_CONFIGURATION_VARIABLES:
        configurationVariables.clear();
        break;
    case FillTheFormDialogModel.PROPERTY_FAST_MODE:
        storeFastModeConfigInSharedPreferences();
        break;
    case FillTheFormDialogModel.PROPERTY_FAST_MODE_BUTTON:
        if (model.isFastModeEnabled()) {
            fastModeButton.setImageResource(R.drawable.ic_fast_mode);
        } else {
            fastModeButton.setImageResource(R.drawable.ic_normal_mode);
        }
        break;
    default:
        break;
    }
}

From source file:im.neon.activity.CommonActivityUtils.java

/**
 * Logout the current user.//from  w w  w. ja  va  2 s.  c o m
 *
 * @param activity      the caller activity
 * @param goToLoginPage true to jump to the login page
 */
public static void logout(final Activity activity, boolean goToLoginPage) {
    // if no activity is provided, use the application context instead.
    final Context context = (null == activity) ? VectorApp.getInstance().getApplicationContext() : activity;

    EventStreamService.removeNotification();
    stopEventStream(context);

    try {
        ShortcutBadger.setBadge(context, 0);
    } catch (Exception e) {
        Log.d(LOG_TAG, "## logout(): Exception Msg=" + e.getMessage());
    }

    // warn that the user logs out
    Collection<MXSession> sessions = Matrix.getMXSessions(context);
    for (MXSession session : sessions) {
        // Publish to the server that we're now offline
        MyPresenceManager.getInstance(context, session).advertiseOffline();
        MyPresenceManager.remove(session);
    }

    // clear the preferences
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    String homeServer = preferences.getString(LoginActivity.HOME_SERVER_URL_PREF,
            context.getResources().getString(R.string.default_hs_server_url));
    String identityServer = preferences.getString(LoginActivity.IDENTITY_SERVER_URL_PREF,
            context.getResources().getString(R.string.default_identity_server_url));
    Boolean useGa = GAHelper.useGA(context);

    SharedPreferences.Editor editor = preferences.edit();
    editor.clear();
    editor.putString(LoginActivity.HOME_SERVER_URL_PREF, homeServer);
    editor.putString(LoginActivity.IDENTITY_SERVER_URL_PREF, identityServer);
    editor.commit();

    if (null != useGa) {
        GAHelper.setUseGA(context, useGa);
    }

    // reset the GCM
    Matrix.getInstance(context).getSharedGCMRegistrationManager().resetGCMRegistration(false);
    // clear the preferences when the application goes to the login screen.
    if (goToLoginPage) {
        Matrix.getInstance(context).getSharedGCMRegistrationManager().clearPreferences();
    }

    // clear credentials
    Matrix.getInstance(context).clearSessions(context, true);

    // ensure that corrupted values are cleared
    Matrix.getInstance(context).getLoginStorage().clear();

    // clear the tmp store list
    Matrix.getInstance(context).clearTmpStoresList();

    // reset the contacts
    PIDsRetriever.getInstance().reset();
    ContactsManager.getInstance().reset();

    MXMediasCache.clearThumbnailsCache(context);

    if (goToLoginPage) {
        if (null != activity) {
            // go to login page
            activity.startActivity(new Intent(activity, LoginActivity.class));
            activity.finish();
        } else {
            Intent intent = new Intent(context, LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            context.startActivity(intent);
        }
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

private static void applyNewDocFlag(Intent i) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {/*from  w  ww  .  ja  va2  s.  c o  m*/

        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME | Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
    }
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void startBreadActivity(Activity from, boolean auth) {
    if (from == null)
        return;/*from ww  w.  ja v a2  s.  c  o m*/
    Log.e(TAG, "startBreadActivity: " + from.getClass().getName());
    Class toStart = auth ? LoginActivity.class : BreadActivity.class;
    Intent intent = new Intent(from, toStart);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    from.startActivity(intent);
    from.overridePendingTransition(R.anim.fade_up, R.anim.fade_down);
    if (!from.isDestroyed()) {
        from.finish();
    }
}

From source file:com.nbplus.vbroadlistener.gcm.MyGcmListenerService.java

private void showNotification(Context context, int notificationId, int smallIconId, String title,
        String contentText, String bigTitle, String bigContentText, String summaryText, String ticker,
        Intent intent) {/*from w  ww.j  a  v a2s .com*/
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);

    if (smallIconId == 0) {
        builder.setSmallIcon(R.mipmap.ic_launcher);
    } else {
        builder.setSmallIcon(smallIconId);
    }
    builder.setWhen(System.currentTimeMillis());
    //builder.setNumber(10);

    if (!StringUtils.isEmptyString(ticker)) {
        builder.setTicker(ticker);
    }

    if (StringUtils.isEmptyString(title)) {
        builder.setContentTitle(PackageUtils.getApplicationName(context));
    } else {
        builder.setContentTitle(title);
    }
    builder.setContentText(contentText);
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    // big title and text
    if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) {
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        if (!StringUtils.isEmptyString(summaryText)) {
            style.setSummaryText(summaryText);
        }
        style.setBigContentTitle(bigTitle);
        style.bigText(bigContentText);

        builder.setStyle(style);
    }

    if (intent != null) {
        intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
    }

    notificationManager.notify(notificationId, builder.build());
}

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

private void showPostUpdateNotification() {
    mShowCount = mUniqueShowIds.size();/*from   w  w w.j  av  a  2 s  . c o  m*/

    // Set up cancel dialog intent
    Intent notificationIntent = new Intent(this, Main.class);
    notificationIntent.putExtra("fromUpdate", true);
    notificationIntent.putExtra("startup", "2");
    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.finishedTvShowsLibraryUpdate));
        mBuilder.setContentTitle(getString(R.string.finishedTvShowsLibraryUpdate));
        mBuilder.setContentText(getString(R.string.stringJustAdded) + " " + mShowCount + " "
                + getResources().getQuantityString(R.plurals.showsInLibrary, mShowCount, mShowCount) + " ("
                + mEpisodeCount + " "
                + getResources().getQuantityString(R.plurals.episodes, mEpisodeCount, mEpisodeCount) + ")");
    } else {
        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) + " " + mShowCount + " "
                + getResources().getQuantityString(R.plurals.showsInLibrary, mShowCount, mShowCount) + " ("
                + mEpisodeCount + " "
                + getResources().getQuantityString(R.plurals.episodes, mEpisodeCount, mEpisodeCount) + ")");
    }
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setAutoCancel(true);

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

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

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