Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

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

Click Source Link

Usage

From source file:Main.java

public static void shareText(Context context, String title, String subject, String text, String mime) {
    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType(mime);/*from  w  w  w .  j  a v a2  s.  c  om*/
    share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);

    // Add data to the intent, the receiving app will decide
    // what to do with it.
    share.putExtra(Intent.EXTRA_SUBJECT, subject);
    share.putExtra(Intent.EXTRA_TEXT, text);

    context.startActivity(Intent.createChooser(share, title));
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getActivityNewDocumentFlag() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    } else {//from   w  w  w .ja  v a2s .  c  o  m
        return Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
}

From source file:Main.java

public static void sendEmail(Context context, String receiver, String subject, String body) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { receiver });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    try {/*from w  w w .j a  v a  2 s.  c o  m*/
        context.startActivity(Intent.createChooser(intent, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
    }
}

From source file:Main.java

/**
 * @return {@link Intent#FLAG_ACTIVITY_NEW_DOCUMENT} on API 21 and above and {@link Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET} on other versions
 *///  w  ww  .ja  v  a2s  .  c o m
@TargetApi(21)
public static int getNewDocumentIntentFlag() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
    } else {
        //noinspection deprecation
        return Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
    }
}

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  .  j  a  va  2 s.c  o  m*/
 *
 * @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

/**
 * When adding account/*from   w w w.  jav  a 2s . c om*/
 * open the same UI screen for user to choose account
 */
public static Intent getIntentForAddingAccount() {
    final Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Settings.EXTRA_AUTHORITIES, new String[] { ContactsContract.AUTHORITY });
    return intent;
}

From source file:Main.java

public static void ShareApplication(Context mContext) {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intent.EXTRA_SUBJECT, "Search Sri Lanka Railway Time Table");
    intent.putExtra(Intent.EXTRA_TITLE, "Search Sri Lanka Railway Time Table");
    intent.putExtra(Intent.EXTRA_TEXT,/*  ww  w .  ja v a 2 s.  com*/
            "Search \"Sri Lanka Railway Time Table\" on your Android. http://market.android.com/details?id=com.aselalee.trainschedule");
    mContext.startActivity(Intent.createChooser(intent, "Spread the word"));
    return;
}

From source file:Main.java

/**
 * Open Calendar app with specific time//ww  w .j ava 2  s . c  om
 */
public static void openCalendar(Activity activity, long epochEventStartTime) {
    Uri uri = Uri.parse("content://com.android.calendar/time/" + epochEventStartTime);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(uri);
    intent.putExtra("VIEW", "DAY");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    activity.startActivity(intent);
}

From source file:Main.java

/**
 * Opens browser with special flags for no history/recents/etc
 * /*from  ww  w  .ja va 2 s  . co  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:Main.java

/**
 * Open an URL in a message./*from   ww w  .  ja  v  a  2s.  c  o  m*/
 *
 * This is intended to mirror the operation of the original
 * (see android.webkit.CallbackProxy) with one addition of intent flags
 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET".  This improves behavior when sublaunching
 * other apps via embedded URI's.
 *
 * We also use this hook to catch "mailto:" links and handle them locally.
 *
 * @param activity parent activity
 * @param url URL to open
 * @param senderAccountId if the URL is mailto:, we use this account as the sender.
 *        TODO When MessageCompose implements the account selector, this won't be necessary.
 *        Pass {@link Account#NO_ACCOUNT} to use the default account.
 * @return true if the URI has successfully been opened.
 */
public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) {
    // hijack mailto: uri's and handle locally
    //***
    //if (url != null && url.toLowerCase().startsWith("mailto:")) {
    //    return MessageCompose.actionCompose(activity, url, senderAccountId);
    //}

    // Handle most uri's via intent launch
    boolean result = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    try {
        activity.startActivity(intent);
        result = true;
    } catch (ActivityNotFoundException ex) {
        // No applications can handle it.  Ignore.
    }
    return result;
}