Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

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

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:Main.java

public static void startSearchPlayApplication(Context mContext, String pkgName) {
    try {//from   w w w  .  j  a  v  a 2  s.  c o m
        Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkgName));
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent);
    } catch (android.content.ActivityNotFoundException anfe) {
        Intent mIntent1 = new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://play.google.com/store/apps/details?id=" + pkgName));
        mIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent1);
    }
}

From source file:Main.java

public static void gotoWeb(Context context, String url) {
    try {/* w w w . j a  va 2  s  .  com*/
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY
                | Intent.FLAG_FROM_BACKGROUND);
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void installApkFileFromUri(Context context, Uri appPath) {
    Intent intent = new Intent();
    intent.setDataAndType(appPath, "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);//  w  w  w  . ja v  a  2s. c o m
}

From source file:Main.java

public static boolean openAppActivity(Context context, String packageName, String activityName) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName cn = new ComponentName(packageName, activityName);
    intent.setComponent(cn);/* w  ww.  j a  v  a2  s.com*/
    try {
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}

From source file:Main.java

public static void jumpPostToNewActivity(final Context context, final Class<? extends Activity> targetClass,
        final int second) {
    (new AsyncTask<String, Integer, Boolean>() {
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep((long) (second * 1000));
            } catch (Exception var3) {
                ;/*from  w w w . j  a  va 2  s  . c o  m*/
            }
            return null;
        }

        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Intent datatIntent = new Intent(context, targetClass);
            datatIntent.setFlags(268435456);
            context.startActivity(datatIntent);
        }
    }).execute(new String[] { "" });
}

From source file:Main.java

public static void jumpPostToNewTopActivity(final Context context, final Class<? extends Activity> targetClass,
        final int second) {
    (new AsyncTask<String, Integer, Boolean>() {
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep((long) (second * 1000));
            } catch (Exception var3) {

            }/*from  ww w  .j av  a 2 s .  c  om*/

            return null;
        }

        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Intent datatIntent = new Intent(context, targetClass);
            datatIntent.setFlags(335544320);
            context.startActivity(datatIntent);
        }
    }).execute(new String[] { "" });
}

From source file:Main.java

/**
 * Opens browser with special flags for no history/recents/etc
 * /*from   ww  w .j av  a2 s  . c  o  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

public static void jumpPostToNewActivity(final Context context, final Class<? extends Activity> targetClass,
        final int second, final String... datas) {
    (new AsyncTask<String, Integer, Boolean>() {
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep((long) (second * 1000));
            } catch (Exception var3) {
                ;//ww w  . ja  va 2s.co m
            }
            return null;
        }

        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Intent datatIntent = new Intent(context, targetClass);
            datatIntent.setFlags(268435456);
            if (datas != null) {
                for (int i = 0; i < datas.length; ++i) {
                    datatIntent.putExtra("data" + i, datas[i]);
                }
            }

            context.startActivity(datatIntent);
        }
    }).execute(new String[] { "" });
}

From source file:Main.java

public static void jumpPostToNewTopActivity(final Context context, final Class<? extends Activity> targetClass,
        final int second, final String... datas) {
    (new AsyncTask<String, Integer, Boolean>() {
        protected Boolean doInBackground(String... params) {
            try {
                Thread.sleep((long) (second * 1000));
            } catch (Exception var3) {
                ;/* w  w w .  ja v  a 2 s.  co  m*/
            }
            return null;
        }

        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Intent datatIntent = new Intent(context, targetClass);
            datatIntent.setFlags(335544320);
            if (datas != null) {
                for (int i = 0; i < datas.length; ++i) {
                    datatIntent.putExtra("data" + i, datas[i]);
                }
            }

            context.startActivity(datatIntent);
        }
    }).execute(new String[] { "" });
}

From source file:Main.java

public static void downloadApkFromBrower(Context context, String url) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    Uri content_url = Uri.parse(url);/*  w w  w .java  2  s  . c o m*/
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(content_url);
    context.startActivity(intent);
}