Example usage for android.support.v4.content IntentCompat FLAG_ACTIVITY_TASK_ON_HOME

List of usage examples for android.support.v4.content IntentCompat FLAG_ACTIVITY_TASK_ON_HOME

Introduction

In this page you can find the example usage for android.support.v4.content IntentCompat FLAG_ACTIVITY_TASK_ON_HOME.

Prototype

int FLAG_ACTIVITY_TASK_ON_HOME

To view the source code for android.support.v4.content IntentCompat FLAG_ACTIVITY_TASK_ON_HOME.

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause a newly launching task to be placed on top of the current home activity task (if there is one).

Usage

From source file:com.doplgangr.secrecy.OutgoingCallReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {

    // Gets the intent, check if it matches our secret code
    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction()) && intent.getExtras() != null) {
        Intent launcher = new Intent(context, MainActivity_.class);
        //These flags are added to make the new mainActivity in the home stack.
        //i.e. back button returns to home not dialer.
        launcher.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
        String phoneNumber = intent.getExtras().getString(android.content.Intent.EXTRA_PHONE_NUMBER);
        if (Pref.OpenPIN().exists())
            if (("*#" + Pref.OpenPIN().get()).equals(phoneNumber))
                // Launch the main app!!
                launchActivity(context, launcher);
    }//w  ww  .ja va2 s  .co m
}

From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java

/**
 * Return an array containing the intents added to this builder. The intent
 * at the root of the task stack will appear as the first item in the array
 * and the intent at the top of the stack will appear as the last item.
 * /*  www  .  java2s  . c  o  m*/
 * @return An array containing the intents added to this builder.
 */
public Intent[] getIntents() {
    Intent[] intents = new Intent[mIntents.size()];
    if (intents.length == 0)
        return intents;

    intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    for (int i = 1; i < intents.length; i++) {
        intents[i] = new Intent(mIntents.get(i));
    }
    return intents;
}

From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java

/**
* Obtain a {@link PendingIntent} for launching the task constructed by this builder so far.
*
* @param requestCode Private request code for the sender
* @param flags May be {@link PendingIntent#FLAG_ONE_SHOT},
*              {@link PendingIntent#FLAG_NO_CREATE}, {@link PendingIntent#FLAG_CANCEL_CURRENT},
*              {@link PendingIntent#FLAG_UPDATE_CURRENT}, or any of the flags supported by
*              {@link Intent#fillIn(Intent, int)} to control which unspecified parts of the
*              intent that can be supplied when the actual send happens.
* @param options Additional options for how the Activity should be started.
* See {@link android.content.Context#startActivity(Intent, Bundle)
* @return The obtained PendingIntent/*from   ww  w.  j av a2  s. c o  m*/
*/
public PendingIntent getPendingIntent(int requestCode, int flags, Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException("No intents added to DualTaskStackBuilder; cannot getPendingIntent");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    // Appropriate flags will be added by the call below.
    return IMPL.getPendingIntent(mSourceContext, intents, requestCode, flags, options);
}

From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java

/**
 * Start the task stack constructed by this builder. The Context used to
 * obtain this builder must be an Activity.
 * /*from   w  ww .ja  va2 s.c  om*/
 * <p>
 * On devices that do not support API level 11 or higher the topmost
 * activity will be started as a new task. On devices that do support API
 * level 11 or higher the new task stack will be created in its entirety.
 * </p>
 * 
 * @param options
 *            Additional options for how the Activity should be started. See
 *            {@link android.content.Context#startActivity(Intent, Bundle)
        
 */
public void startActivities(Bundle options) {
    if (mIntents.isEmpty()) {
        throw new IllegalStateException("No intents added to DualTaskStackBuilder; cannot startActivities");
    }

    Intent[] intents = mIntents.toArray(new Intent[mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | IntentCompat.FLAG_ACTIVITY_TASK_ON_HOME);
    if (!ContextCompat.startActivities(mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mSourceContext.startActivity(topIntent);
    }
}