Example usage for android.content Intent FLAG_ACTIVITY_NO_HISTORY

List of usage examples for android.content Intent FLAG_ACTIVITY_NO_HISTORY

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_NO_HISTORY.

Prototype

int FLAG_ACTIVITY_NO_HISTORY

To view the source code for android.content Intent FLAG_ACTIVITY_NO_HISTORY.

Click Source Link

Document

If set, the new activity is not kept in the history stack.

Usage

From source file:Main.java

public static void gotoWeb(Context context, String url) {
    try {//from   w ww.  ja  va 2 s.c om
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY
                | Intent.FLAG_FROM_BACKGROUND);
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Tries to open the app store by using the passed storeAppUri. If this
 * fails, opens the store website.//from w  w w  . ja va 2  s.com
 *
 * @param ctx             The Android context.
 * @param storeAppUri     The app store uri.
 * @param storeWebsiteUri The store website.
 */
public static void openAppStore(Context ctx, Uri storeAppUri, Uri storeWebsiteUri) {
    Intent marketIntent;

    try {
        marketIntent = new Intent(Intent.ACTION_VIEW, storeAppUri);
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ctx.startActivity(marketIntent);

    } catch (android.content.ActivityNotFoundException anfe) {
        marketIntent = new Intent(Intent.ACTION_VIEW, storeWebsiteUri);
        marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        ctx.startActivity(marketIntent);
    }
}

From source file:Main.java

public static void displayError(String message, final Class<?> activity, final Context context) {
    // no deals found so display a popup and return to search options
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    // set title/*ww w  .  j av a2  s.c  om*/
    builder.setTitle("No Results");

    // set dialog message
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    Intent i = new Intent(context, activity);
                    ((Activity) (context)).finish();
                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
                    context.startActivity(i);
                }
            });
    // create alert dialog
    AlertDialog alertDialog = builder.create();

    // show it
    alertDialog.show();
}

From source file:Main.java

public static void startInstalledAppDetailsActivity(@Nullable final Activity context) {
    if (context == null) {
        return;/*  w w w .  ja va  2s .  c  om*/
    }
    final Intent i = new Intent();
    i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
    i.addCategory(Intent.CATEGORY_DEFAULT);
    i.setData(Uri.parse("package:" + context.getPackageName()));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    context.startActivity(i);
}

From source file:Main.java

/**
 * Opens browser with special flags for no history/recents/etc
 * /*from  w w  w .j  a va 2 s  .c  o  m*/
 * @param ctx
 *            context to use
 * @param url
 *            url to open
 */
public static void openNoHistory(Context ctx, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    ctx.startActivity(intent);
}

From source file:com.numenta.htmit.mobile.notification.NotificationUtils.java

/**
 * Create {@link MetricDetailActivity} {@link Intent} configured to be used
 * as the notification result intent for the given notification and the
 * given metric/* w w w .  j a  va2s. c  o  m*/
 *
 * @param ctx The {@link Context}
 * @param notification The {@link Notification}
 * @return A new {@link Intent} that will open the
 *         {@link MetricDetailActivity} showing the metric data associated
 *         with the notification.
 * @see #createOSNotification(String, long, int, long)
 * @see NotificationListActivity
 */
public static Intent createMetricDetailIntent(final Context ctx, final Notification notification) {
    final HTMITDatabase database = HTMITApplication.getDatabase();
    final Metric metric = database.getMetric(notification.getMetricId());
    final Intent resultIntent = new Intent(ctx, MetricDetailActivity.class);
    resultIntent.setFlags(
            Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
            // | Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    resultIntent.putExtra(MetricDetailActivity.EXTRA_METRIC, metric.getId());
    resultIntent.putExtra(MetricDetailActivity.EXTRA_DATE, notification.getTimestamp());
    return resultIntent;

}

From source file:com.groksolutions.grok.mobile.notification.NotificationUtils.java

/**
 * Create {@link MetricDetailActivity} {@link Intent} configured to be used
 * as the notification result intent for the given notification and the
 * given metric/*from  w ww.java2s .  c o  m*/
 *
 * @param ctx The {@link Context}
 * @param notification The {@link Notification}
 * @return A new {@link Intent} that will open the
 *         {@link MetricDetailActivity} showing the metric data associated
 *         with the notification.
 * @see #createOSNotification(String, long, int, long)
 * @see NotificationListActivity
 */
public static Intent createMetricDetailIntent(final Context ctx, final Notification notification) {
    final GrokDatabase grokDb = HTMITApplication.getDatabase();
    final Metric metric = grokDb.getMetric(notification.getMetricId());
    final Intent resultIntent = new Intent(ctx, MetricDetailActivity.class);
    resultIntent.setFlags(
            Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
            // | Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    resultIntent.putExtra(MetricDetailActivity.EXTRA_METRIC, metric.getId());
    resultIntent.putExtra(MetricDetailActivity.EXTRA_DATE, notification.getTimestamp());
    return resultIntent;

}

From source file:com.YOMPsolutions.YOMP.mobile.notification.NotificationUtils.java

/**
 * Create {@link MetricDetailActivity} {@link Intent} configured to be used
 * as the notification result intent for the given notification and the
 * given metric//from   w w  w. ja va2s .co m
 *
 * @param ctx The {@link Context}
 * @param notification The {@link Notification}
 * @return A new {@link Intent} that will open the
 *         {@link MetricDetailActivity} showing the metric data associated
 *         with the notification.
 * @see #createOSNotification(String, long, int, long)
 * @see NotificationListActivity
 */
public static Intent createMetricDetailIntent(final Context ctx, final Notification notification) {
    final YOMPDatabase YOMPDb = YOMPApplication.getDatabase();
    final Metric metric = YOMPDb.getMetric(notification.getMetricId());
    final Intent resultIntent = new Intent(ctx, MetricDetailActivity.class);
    resultIntent.setFlags(
            Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
            // | Intent.FLAG_ACTIVITY_SINGLE_TOP
                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    resultIntent.putExtra(MetricDetailActivity.EXTRA_METRIC, metric.getId());
    resultIntent.putExtra(MetricDetailActivity.EXTRA_DATE, notification.getTimestamp());
    return resultIntent;

}

From source file:com.github.fi3te.iliasdownloader.controller.Util.java

public static void openFile(File file, Activity forMessages) {
    if (file != null && forMessages != null && file.isFile()) {
        String extension = FilenameUtils.getExtension(file.getPath());
        if (extension.length() > 0) {
            try {
                extension = extension.toLowerCase();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file),
                        MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension));
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                forMessages.startActivity(intent);
            } catch (ActivityNotFoundException anfe) {
                Toast.makeText(forMessages, forMessages.getResources().getString(R.string.unknown_type),
                        Toast.LENGTH_SHORT).show();
            }//from   ww  w .j  av  a 2s .c o  m
        }
    }
}

From source file:de.baumann.quitsmoking.helper.helper_main.java

public static void openFile(Activity activity, File file, String string, View view) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = FileProvider.getUriForFile(activity,
                activity.getApplicationContext().getPackageName() + ".provider", file);
        intent.setDataAndType(contentUri, string);

    } else {//from w  w  w  .j a va 2 s . c om
        intent.setDataAndType(Uri.fromFile(file), string);
    }

    try {
        activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show();
    }
}