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:org.gnucash.android.ui.homescreen.WidgetConfigurationActivity.java

/**
 * Updates the widget with id <code>appWidgetId</code> with information from the 
 * account with record ID <code>accountId</code>
  * If the account has been deleted, then a notice is posted in the widget
 * @param appWidgetId ID of the widget to be updated
 *//*ww  w.  j  a  v  a 2 s .  c o m*/
public static void updateWidget(final Context context, int appWidgetId) {
    Log.i("WidgetConfiguration", "Updating widget: " + appWidgetId);
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    loadOldPreferences(context, appWidgetId);

    SharedPreferences preferences = context.getSharedPreferences("widget:" + appWidgetId, MODE_PRIVATE);
    String bookUID = preferences.getString(UxArgument.BOOK_UID, null);
    String accountUID = preferences.getString(UxArgument.SELECTED_ACCOUNT_UID, null);
    boolean hideAccountBalance = preferences.getBoolean(UxArgument.HIDE_ACCOUNT_BALANCE_IN_WIDGET, false);

    if (bookUID == null || accountUID == null) {
        return;
    }

    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(BookDbHelper.getDatabase(bookUID));

    final Account account;
    try {
        account = accountsDbAdapter.getRecord(accountUID);
    } catch (IllegalArgumentException e) {
        Log.i("WidgetConfiguration", "Account not found, resetting widget " + appWidgetId);
        //if account has been deleted, let the user know
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
        views.setTextViewText(R.id.account_name, context.getString(R.string.toast_account_deleted));
        views.setTextViewText(R.id.transactions_summary, "");
        //set it to simply open the app
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, AccountsActivity.class), 0);
        views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);
        views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, views);
        Editor editor = PreferenceActivity.getActiveBookSharedPreferences().edit(); //PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.remove(UxArgument.SELECTED_ACCOUNT_UID + appWidgetId);
        editor.apply();
        return;
    }

    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
    views.setTextViewText(R.id.account_name, account.getName());

    Money accountBalance = accountsDbAdapter.getAccountBalance(accountUID, -1, System.currentTimeMillis());

    if (hideAccountBalance) {
        views.setViewVisibility(R.id.transactions_summary, View.GONE);
    } else {
        views.setTextViewText(R.id.transactions_summary, accountBalance.formattedString(Locale.getDefault()));
        int color = accountBalance.isNegative() ? R.color.debit_red : R.color.credit_green;
        views.setTextColor(R.id.transactions_summary, context.getResources().getColor(color));
    }

    Intent accountViewIntent = new Intent(context, TransactionsActivity.class);
    accountViewIntent.setAction(Intent.ACTION_VIEW);
    accountViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    accountViewIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, accountUID);
    accountViewIntent.putExtra(UxArgument.BOOK_UID, bookUID);
    PendingIntent accountPendingIntent = PendingIntent.getActivity(context, appWidgetId, accountViewIntent, 0);
    views.setOnClickPendingIntent(R.id.widget_layout, accountPendingIntent);

    if (accountsDbAdapter.isPlaceholderAccount(accountUID)) {
        views.setOnClickPendingIntent(R.id.btn_view_account, accountPendingIntent);
        views.setViewVisibility(R.id.btn_new_transaction, View.GONE);
    } else {
        Intent newTransactionIntent = new Intent(context, FormActivity.class);
        newTransactionIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
        newTransactionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newTransactionIntent.putExtra(UxArgument.FORM_TYPE, FormActivity.FormType.TRANSACTION.name());
        newTransactionIntent.putExtra(UxArgument.BOOK_UID, bookUID);
        newTransactionIntent.putExtra(UxArgument.SELECTED_ACCOUNT_UID, accountUID);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, newTransactionIntent, 0);
        views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);
        views.setViewVisibility(R.id.btn_view_account, View.GONE);
    }

    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java

private void finishSetup() {
    Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
    ((CMAccount) AppGlobals.getInitialApplication()).enableStatusBar();
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    disableSetupWizards(intent);/*from www.  j  a v  a2s  .  c om*/
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
    startActivity(intent);
    finish();
}

From source file:com.zaparound.MyFirebaseMessagingService.java

/**
 * Create and show a Inmylocation Notification.
 *
 * @param messageBody FCM message body received.
 *///from   w  w  w  . j a  v a2s .  co m
private void sendNotificationInmylocation(String messagetitle, String messageBody) {
    Intent intent = new Intent(this, LandingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CHATTAB_POSITION", 3);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0)
            .setAutoCancel(true).setContentTitle(messagetitle)
            //.setNumber(++count)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            //.setSubText("\n "+count+" new messages\n")
            .setContentIntent(pendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo))
            .setContentText(messageBody).build();

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:the.joeapollo.utils.ApolloUtils.java

/**
 * Used to create shortcuts for an artist, album, or playlist that is then
 * placed on the default launcher homescreen
 * //from  w  w w . j a  v  a2 s.  c o  m
 * @param displayName The shortcut name
 * @param id The ID of the artist, album, playlist, or genre
 * @param mimeType The MIME type of the shortcut
 * @param context The {@link Context} to use to
 */
public static void createShortcutIntent(final String displayName, final Long id, final String mimeType,
        final SherlockFragmentActivity context) {
    try {
        final ImageFetcher fetcher = getImageFetcher(context);
        Bitmap bitmap = null;
        if (mimeType.equals(MediaStore.Audio.Albums.CONTENT_TYPE)) {
            bitmap = fetcher.getCachedBitmap(displayName + Config.ALBUM_ART_SUFFIX);
        } else {
            bitmap = fetcher.getCachedBitmap(displayName);
        }
        if (bitmap == null) {
            bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_artwork);
        }

        // Intent used when the icon is touched
        final Intent shortcutIntent = new Intent(context, ShortcutActivity.class);
        shortcutIntent.setAction(Intent.ACTION_VIEW);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Config.ID, id);
        shortcutIntent.putExtra(Config.NAME, displayName);
        shortcutIntent.putExtra(Config.MIME_TYPE, mimeType);

        // Intent that actually sets the shortcut
        final Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtils.resizeAndCropCenter(bitmap, 96));
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        context.sendBroadcast(intent);
        Toast.makeText(context, displayName + " " + context.getString(R.string.pinned_to_home_screen),
                Toast.LENGTH_LONG).show();
    } catch (final Exception e) {
        Log.e("ApolloUtils", "createShortcutIntent - " + e);
        Toast.makeText(context,
                displayName + " " + context.getString(R.string.could_not_be_pinned_to_home_screen),
                Toast.LENGTH_LONG).show();
    }
}

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

private void sendNotification(String message) {
    Intent intent = new Intent(this, AcceptActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER")
            .setContentText("? ").setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.andrew.apollo.utils.ApolloUtils.java

/**
 * Used to create shortcuts for an artist, album, or playlist that is then
 * placed on the default launcher homescreen
 * /*w  ww  .  j  a v  a2 s.c  om*/
 * @param displayName The shortcut name
 * @param id The ID of the artist, album, playlist, or genre
 * @param mimeType The MIME type of the shortcut
 * @param context The {@link Context} to use to
 */
public static void createShortcutIntent(final String displayName, final Long id, final String mimeType,
        final SherlockFragmentActivity context) {
    try {
        final ImageFetcher fetcher = getImageFetcher(context);
        Bitmap bitmap = null;
        if (mimeType.equals(MediaStore.Audio.Albums.CONTENT_TYPE)) {
            bitmap = fetcher.getCachedBitmap(displayName + Config.ALBUM_ART_SUFFIX);
        } else {
            bitmap = fetcher.getCachedBitmap(displayName);
        }
        if (bitmap == null) {
            bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.default_artwork);
        }

        // Intent used when the icon is touched
        final Intent shortcutIntent = new Intent(context, ShortcutActivity.class);
        shortcutIntent.setAction(Intent.ACTION_VIEW);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Config.ID, id);
        shortcutIntent.putExtra(Config.NAME, displayName);
        shortcutIntent.putExtra(Config.MIME_TYPE, mimeType);

        // Intent that actually sets the shortcut
        final Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapUtils.resizeAndCropCenter(bitmap, 96));
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        context.sendBroadcast(intent);
        Crouton.makeText(context, displayName + " " + context.getString(R.string.pinned_to_home_screen),
                Crouton.STYLE_CONFIRM).show();
    } catch (final Exception e) {
        Log.e("ApolloUtils", "createShortcutIntent - " + e);
        Crouton.makeText(context,
                displayName + " " + context.getString(R.string.could_not_be_pinned_to_home_screen),
                Crouton.STYLE_ALERT).show();
    }
}

From source file:eu.operando.proxy.OperandoProxyStatus.java

private void reloadActivity() {
    finish();//from   w ww  .j av a2 s  .c om
    Intent intent = new Intent(this, MainProxyActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:com.fsck.k9.activity.Accounts.java

public static void listAccounts(Context context) {
    Intent intent = new Intent(context, Accounts.class);

    if (Build.VERSION.SDK_INT >= 11) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    } else {//from www  .  jav a 2s .c  o m
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    }

    intent.putExtra(EXTRA_STARTUP, false);
    context.startActivity(intent);
}

From source file:org.catnut.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // open or close the drawer
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from  w w w.  j a  v a  2s . co  m
    switch (item.getItemId()) {
    // killapp??back???back stack
    case R.id.logout:
        new AlertDialog.Builder(this).setMessage(getString(R.string.logout_confirm))
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Process.killProcess(Process.myPid());
                    }
                }).setNegativeButton(android.R.string.no, null).show();
        break;
    // ???
    case R.id.cancellation:
        new AlertDialog.Builder(this).setMessage(getString(R.string.cancellation_confirm))
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mApp.invalidateAccessToken();
                        Intent intent = new Intent(MainActivity.this, HelloActivity.class);
                        // ?back stack
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    }
                }).setNegativeButton(android.R.string.no, null).show();
        break;
    case R.id.pref:
        startActivity(SingleFragmentActivity.getIntent(this, SingleFragmentActivity.PREF));
        break;
    case R.id.action_compose:
        startActivity(new Intent(this, ComposeTweetActivity.class));
        break;
    case R.id.fantasy:
        startActivity(new Intent(this, HelloActivity.class).putExtra(HelloActivity.TAG, HelloActivity.TAG));
        break;
    case R.id.plugins:
        switch2Plugins(null);
        break;
    case R.id.action_refresh_news_count:
        fetchNews();
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

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

public void backButton() {
    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.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);
}