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

public static void install(Activity activity, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    activity.startActivity(intent);//from w w  w .  j a  v a  2s.com
}

From source file:Main.java

public static void installApk(Context context, String filePath) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
    context.startActivity(intent);/*w  w w.  j a va 2 s  .  co  m*/
}

From source file:Main.java

private static void prepareRestartAppIntent(Intent i) {
    i.setAction(Intent.ACTION_MAIN);//from ww w .j  ava 2s.co  m
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}

From source file:Main.java

public static void goHome(Activity currentActivity, Class<?> homeActivityClass) {
    Intent parentActivityIntent = new Intent(currentActivity, homeActivityClass);
    parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    currentActivity.startActivity(parentActivityIntent);
    currentActivity.finish();//  ww w.j  a  v a2s  . co  m
}

From source file:Main.java

public static void startActivityWithNewTask(@NonNull Context context, @NonNull Class className) {
    Intent intent = new Intent(context, className);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);/*from   w w  w .  ja  v a 2s  .c  o  m*/
}

From source file:Main.java

public static void uninstallApp(Context context, String packageName) {
    Uri uri = Uri.parse("package:" + packageName);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);/*from w w w . j  ava  2s .  c om*/
}

From source file:Main.java

/**
 * @param packageName/*  w ww. ja  va  2s .  c o m*/
 * @param context
 */
public static void openApp(String packageName, Context context) {

    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);

    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    resolveIntent.setPackage(packageName);

    List<ResolveInfo> apps = context.getPackageManager().queryIntentActivities(resolveIntent, 0);

    ResolveInfo ri = apps.iterator().next();

    if (ri != null) {

        String packageName_i = ri.activityInfo.packageName;

        String className_i = ri.activityInfo.name;

        Intent intent = new Intent(Intent.ACTION_MAIN);

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        ComponentName cn = new ComponentName(packageName_i, className_i);

        intent.setComponent(cn);

        context.startActivity(intent);

    }

}

From source file:Main.java

public static Intent getSettingLSThemeIntent() {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.asus.themeapp", "com.asus.themeapp.ThemeAppActivity"));
    intent.addFlags(/*w  w  w  .  j a  v a  2 s. c  o m*/
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("from", "com.android.systemui.lockscreen");
    return intent;
}

From source file:Main.java

public static Intent getSettingLSWallpaperIntent() {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.asus.launcher", "com.asus.themeapp.ThemeAppActivity"));
    intent.addFlags(//  w  w  w.  j a  va2  s. com
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("tabPosition", 1);
    return intent;
}

From source file:Main.java

public static void openImage(Context mContext, String imagePath) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    Uri uri = Uri.fromFile(new File(imagePath));
    intent.setDataAndType(uri, "image/*");
    mContext.startActivity(intent);//from   www .j  a v a  2s . c om
}