Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:Main.java

private static void organizeAndStart(Activity activity, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(activity, classes);
    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }//from w  w  w  .ja v a  2 s.c o  m
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(intent);
}

From source file:Main.java

public static void clearActivityTask(final Context context) {
    Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(i);/*from  w ww  .  j  a  v a 2 s . c o  m*/
    ((Activity) context).finish();

}

From source file:Main.java

private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(context, classes);

    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }//from ww w. j  a  v  a2  s . c o m
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:Main.java

private static void prepareRestartAppIntent(Intent i) {
    i.setAction(Intent.ACTION_MAIN);//from w  w  w.  jav  a 2  s. c o  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();/*from  ww w  .  j a va 2s. c o  m*/
}

From source file:Main.java

public static void newClearTask(Activity activity, Class<?> homeActivityClass) {
    activity.finish();/*from   ww  w  .  j  av  a 2s  .  com*/
    Intent intent = new Intent(activity, homeActivityClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    activity.startActivity(intent);
}

From source file:Main.java

public static void openVideo(Context mContext, String videoPath) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("oneshot", 0);
    intent.putExtra("configchange", 0);
    Uri uri = Uri.fromFile(new File(videoPath));
    intent.setDataAndType(uri, "video/*");
    mContext.startActivity(intent);//from  w  w  w  .  j a  va2  s  . c o m
}

From source file:Main.java

public static void displayError(String message, final Class<?> activity, final Context context) {
    // no deals found so display a popup and return to search options
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    // set title//from w  ww .  j  a va  2  s . co m
    builder.setTitle("No Results");

    // set dialog message
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    Intent i = new Intent(context, activity);
                    ((Activity) (context)).finish();
                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
                    context.startActivity(i);
                }
            });
    // create alert dialog
    AlertDialog alertDialog = builder.create();

    // show it
    alertDialog.show();
}

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(/*from  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(//from  w w w  .  j a v a2s.c  o m
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra("tabPosition", 1);
    return intent;
}