Java Code Examples for android.support.v4.content.ContextCompat#startActivities()

The following examples show how to use android.support.v4.content.ContextCompat#startActivities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseActivityLauncher.java    From SmartGo with Apache License 2.0 6 votes vote down vote up
@Override
public void goReally(final Context context,final Intent intent){
    if(isAvailable(context,intent)) {
        final ActivityOptionsCompat options = mActivityOptionsBox.get();
        Bundle optionsBundle = null;
        if(options != null) {
            optionsBundle = options.toBundle();
        }

        if(context instanceof Activity) {
            ActivityCompat.startActivityForResult((Activity) context, intent, mRequestCode, optionsBundle);
        }else {
            ContextCompat.startActivities(context,new Intent[]{intent},optionsBundle);
        }
    }else{
        SmartGoLog.e("have no resolved activity : " + intent);
    }
}
 
Example 2
Source File: TaskStackBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <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 TaskStackBuilder; 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);
    }
}
 
Example 3
Source File: TaskStackBuilder.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <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 TaskStackBuilder; 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);
    }
}
 
Example 4
Source File: TaskStackBuilder.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <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 TaskStackBuilder; 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);
    }
}
 
Example 5
Source File: TaskStackBuilder.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <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 TaskStackBuilder; 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);
    }
}
 
Example 6
Source File: TaskStackBuilder.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Start the task stack constructed by this builder. The Context used to obtain
 * this builder must be an Activity.
 *
 * <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 TaskStackBuilder; 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);
    }
}
 
Example 7
Source File: TaskStackBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public void startActivities(Bundle options) {
    if (this.mIntents.isEmpty()) {
        throw new IllegalStateException("No intents added to TaskStackBuilder; cannot startActivities");
    }
    Intent[] intents = (Intent[]) this.mIntents.toArray(new Intent[this.mIntents.size()]);
    intents[0] = new Intent(intents[0]).addFlags(268484608);
    if (!ContextCompat.startActivities(this.mSourceContext, intents, options)) {
        Intent topIntent = new Intent(intents[intents.length - 1]);
        topIntent.addFlags(268435456);
        this.mSourceContext.startActivity(topIntent);
    }
}
 
Example 8
Source File: TaskStackBuilder.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void startActivities(Bundle bundle)
{
    if (c.isEmpty())
    {
        throw new IllegalStateException("No intents added to TaskStackBuilder; cannot startActivities");
    }
    Intent aintent[] = (Intent[])c.toArray(new Intent[c.size()]);
    aintent[0] = (new Intent(aintent[0])).addFlags(0x1000c000);
    if (!ContextCompat.startActivities(d, aintent, bundle))
    {
        Intent intent = new Intent(aintent[-1 + aintent.length]);
        intent.addFlags(0x10000000);
        d.startActivity(intent);
    }
}
 
Example 9
Source File: ContextUtil.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean startActivities(Intent[] intents, Bundle options) {
    for (Intent intent : intents)
        if (intent != null)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return ContextCompat.startActivities(Base.getContext(), intents, options);
}
 
Example 10
Source File: ContextUtil.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean startActivities(Intent[] intents) {
    for (Intent intent : intents)
        if (intent != null)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return ContextCompat.startActivities(Base.getContext(), intents);
}