Start a new activity and clear all tasks and disable history (back stack) - Android Activity

Android examples for Activity:Activity Start

Description

Start a new activity and clear all tasks and disable history (back stack)

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.Intent;

public class Main {
    /**/* w ww  .j  a va  2 s . c o m*/
     * Start a new activity and clear all tasks and disable history (back stack)
     *
     * @param currentActivity current activity
     * @param activityToStart class activity to start
     */
    public static void startActivityAndClearTasks(Activity currentActivity,
            Class<?> activityToStart) {
        Intent intent = new Intent(currentActivity, activityToStart);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        currentActivity.startActivity(intent);
    }
}

Related Tutorials