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

/**
 * Restart application (just relauch the first page of package)
 *
 *
 * @param context Context/*from  w  ww.j a va2  s.  com*/
 */
public static void restartApplication(Context context) {
    final Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:anakiou.com.picontrol.ui.activities.MainMenuActivity.java

public static Intent newIntent(Context context) {
    Intent intent = new Intent(context, MainMenuActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    return intent;
}

From source file:com.agna.setmaster.ui.screen.main.MainActivity.java

public static void start(Activity activity) {
    Intent i = new Intent(activity, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.finish();/*from  w w w  . j a v  a 2 s  .  com*/
    activity.startActivity(i);
}

From source file:Main.java

public static void restartClearActivity(Activity activity) {
    if (activity == null)
        return;//from   ww  w.j ava 2s.  c  om
    Context ctx = activity.getApplicationContext();
    Intent intent;
    intent = activity.getIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    activity.finish();
    activity.overridePendingTransition(0, 0);

    ctx.startActivity(intent);
    activity.overridePendingTransition(0, 0);

}

From source file:Main.java

public static void restartClearActivityOutside(Activity activity) {
    if (activity == null)
        return;/*from w ww .  ja  v  a2  s  .c o m*/
    Context ctx = activity.getApplicationContext();
    Intent intent;
    intent = activity.getIntent();
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    activity.finish();
    activity.overridePendingTransition(0, 0);

    ctx.startActivity(intent);
    activity.overridePendingTransition(0, 0);

}

From source file:Main.java

public static boolean startActivityUsingScheme(Context a, String scheme) {
    Uri uri = Uri.parse(scheme + "://");
    Intent intent = new Intent(Intent.ACTION_RUN, uri);
    boolean result = true;
    try {/*from   w  w  w .j  av  a2  s  .  co  m*/
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        a.startActivity(intent);
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = false;
    }
    return result;
}

From source file:Main.java

public static void restartActivity(Activity activity) {

    if (activity == null)
        return;// ww w.j a  va2 s .  co 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 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);//from   w  ww  .  jav  a2  s. c o m

    return conversations;
}

From source file:Main.java

/**
 * Finish the given activity and start a home activity class.
 * <p/>/*from www. ja  v a2 s .co  m*/
 * This mirror the behavior of the home action bar button that clears the
 * current activity and starts or brings another activity to the top.
 *
 * @param activity
 * @param homeActivityClass
 */
public static void goHome(Activity activity, Class<?> homeActivityClass) {
    activity.finish();
    Intent intent = new Intent(activity, homeActivityClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);
}

From source file:Main.java

/**
 * Returns an implicit intent for opening QuickContacts.
 *///from w w  w . j a  v  a2 s. com
public static Intent composeQuickContactIntent(Uri contactLookupUri, int extraMode) {
    final Intent intent = new Intent(QuickContact.ACTION_QUICK_CONTACT);
    intent.setData(contactLookupUri);
    intent.putExtra(QuickContact.EXTRA_MODE, extraMode);
    // Make sure not to show QuickContacts on top of another QuickContacts.
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return intent;
}