Example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_SINGLE_TOP

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

Click Source Link

Document

If set, the activity will not be launched if it is already running at the top of the history stack.

Usage

From source file:Main.java

public static void CloseActivity(Activity activity, Class<?> class1) {
    Intent intent = new Intent(activity, class1);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);/*ww w  .  jav a2s. c om*/
}

From source file:Main.java

public static void putData(Context context, Class<?> activity, String key, String value) {
    Intent intent = new Intent();
    intent.setClass(context, activity);/* w  w  w.ja v  a 2s . c  o m*/
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(key, value);
    context.startActivity(intent);
}

From source file:Main.java

public static void gotoWeb(Context context, String url) {
    try {//from w ww. j  a  v a  2 s .  co m
        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

/**
 * Goes back to the specific activity if it was already created and clears stack
 * on top of it//from  w w  w. j  a  v a2  s  .co m
 * @param context context to work in
 * @param activityToGoBack activity class to go back to
 */
public static void goBackTo(Context context, Class<? extends Activity> activityToGoBack) {
    Intent intent = new Intent(context, activityToGoBack);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    context.startActivity(intent);
}

From source file:Main.java

/**
 * Get the intent used to open installation U.I.
 *
 * @param fileUri downloaded file URI from the download manager.
 * @return intent to open installation U.I.
 *//*from w  ww  .  j a  v  a2s  .  c o  m*/
@NonNull
static Intent getInstallIntent(Uri fileUri) {
    Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
    intent.setData(fileUri);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return intent;
}

From source file:Main.java

public static void newClearTask(Activity activity, Class<?> homeActivityClass) {
    activity.finish();//w  w  w. j a  v a 2s .  c  o  m
    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 Intent getSettingLSThemeIntent() {
    Intent intent = new Intent();
    intent.setComponent(new ComponentName("com.asus.themeapp", "com.asus.themeapp.ThemeAppActivity"));
    intent.addFlags(// ww w .  j av 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  v  a  2 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 startActivity(Context context, Class<?> clazz) {
    Intent intent = new Intent(context, clazz);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    context.startActivity(intent);/*from   www . j  a  v  a2 s. c o  m*/
}

From source file:Main.java

public static Intent getSmsIntent() {
    Intent conversations = new Intent(Intent.ACTION_MAIN);
    //conversations.addCategory(Intent.CATEGORY_DEFAULT);
    conversations.setType(SMS_MIME_TYPE);
    // should I be using FLAG_ACTIVITY_RESET_TASK_IF_NEEDED??
    int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TOP;
    conversations.setFlags(flags);//w  w  w. j a va2s.c  o  m

    return conversations;
}