Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_NEW_TASK

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

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:Main.java

/**
 * Used to search the Play Store for a specific app.
 * //from w  ww.  j av a2  s  .co m
 * @param context The {@link Context} to use.
 * @param themeName The theme name to search for.
 */
public static void openAppPage(final Context context, final String themeName) {
    final Intent shopIntent = new Intent(Intent.ACTION_VIEW);
    shopIntent.setData(Uri.parse(APP_URI + themeName));
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shopIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(shopIntent);
}

From source file:Main.java

/**
 * start app/*from ww w. ja  v  a 2 s. c  o  m*/
 *
 * @param ctx
 * @param packageName
 */
public static void startApp(Context ctx, String packageName) {

    if (!isAppInstalled(ctx, packageName)) {
        return;
    }

    PackageManager packageManager = ctx.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    ctx.startActivity(intent);
}

From source file:Main.java

public static void restartActivity(Activity activity) {

    if (activity == null)
        return;/*  ww  w . ja va  2  s.  c o  m*/

    if (Build.VERSION.SDK_INT >= 11) {
        activity.recreate();
    } else {
        Intent intent;
        intent = activity.getIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.finish();
        activity.overridePendingTransition(0, 0);
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }

}

From source file:Main.java

public static void installApk(Context context, File file) {

    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setType("application/vnd.android.package-archive");
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);// ww  w . ja  va2  s  .  c  o  m

}

From source file:Main.java

public static void startInstalledAppDetailsActivity(@Nullable final Activity context) {
    if (context == null) {
        return;/*from ww  w .  j a  v a 2 s  . 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

public static void startMarket(Context context, String packageName, String referrer) {
    String referrerParam = referrer != null ? "&referrer=" + referrer : "";
    try {/*from w  w  w.jav a 2  s. co m*/
        Uri uri = Uri.parse("market://details?id=" + packageName + referrerParam);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (ActivityNotFoundException anfe) {
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + packageName + referrerParam));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}

From source file:Main.java

/**
 * Load the settings activity of a particular joyn client to enable or
 * disable the client/*from   ww w  . j  a  v  a 2  s .  c o  m*/
 * 
 * @param context Application context
 * @param appInfo Application info
 */
public static void loadJoynClientSettings(Context context, ResolveInfo appInfo) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(new ComponentName(appInfo.activityInfo.packageName, appInfo.activityInfo.name));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(intent);
}

From source file:Main.java

private static void shareImageOnFacebook(String imagePath, Context context) {

    Log.d("CitationsManager-ShareOnFb", "sharing the image " + imagePath);
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    // shareIntent.putExtra(Intent.EXTRA_TEXT, "www.google.com");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
    for (final ResolveInfo app : activityList) {

        Log.d("CitationsManager-ShareOnFb", app.activityInfo.name);
        if ((app.activityInfo.name).contains("com.facebook") && !(app.activityInfo.name).contains("messenger")
                && !(app.activityInfo.name).contains("pages")) {
            final ActivityInfo activity = app.activityInfo;
            final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
            shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            shareIntent.setComponent(name);
            context.startActivity(shareIntent);
            break;
        }/*from  w ww .  j av a  2  s  .co m*/
    }

}

From source file:Main.java

public static void openURL(final Context ctx, final String url) {
    final Intent i2 = new Intent(Intent.ACTION_VIEW);
    i2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i2.setData(Uri.parse(url));//from w  w  w . j  a  v  a  2  s. c o  m
    ctx.startActivity(i2);
}

From source file:Main.java

public static void start(Context paramContext, String paramString) {
    Uri localUri = Uri.parse(paramString);
    Intent localIntent = new Intent("android.intent.action.VIEW", localUri);
    localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    paramContext.startActivity(localIntent);
}