Example usage for android.support.v4.app NavUtils shouldUpRecreateTask

List of usage examples for android.support.v4.app NavUtils shouldUpRecreateTask

Introduction

In this page you can find the example usage for android.support.v4.app NavUtils shouldUpRecreateTask.

Prototype

public static boolean shouldUpRecreateTask(Activity sourceActivity, Intent targetIntent) 

Source Link

Document

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

Usage

From source file:Main.java

public static void standardUp(Activity activity) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities();
    } else {/*from   www  . j  a v a2  s  .c  o m*/
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        activity.startActivity(upIntent);
        activity.finish();
    }
}

From source file:Main.java

public static void navigateUp(Activity activity, Bundle extras) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (upIntent != null) {
        if (extras != null) {
            upIntent.putExtras(extras);//w w w . ja v  a 2 s  .  co m
        }
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(activity)
                    // Add all of this activity's parents to the back stack.
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent.
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            // According to http://stackoverflow.com/a/14792752/2420519
            //NavUtils.navigateUpTo(activity, upIntent);
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(upIntent);
        }
    }
    activity.finish();
}

From source file:com.dgsd.android.ShiftTracker.StApp.java

public static void doDefaultNavigateUp(Activity a) {
    Intent upIntent = new Intent(a, StApp.getHomeClass(a));
    if (NavUtils.shouldUpRecreateTask(a, upIntent)) {
        TaskStackBuilder.create(a).addNextIntent(upIntent).startActivities();
        a.finish();/*from   w w w . j  av a 2 s.  c om*/
    } else {
        NavUtils.navigateUpTo(a, upIntent);
    }
}

From source file:com.richtodd.android.quiltdesign.app.FileSelectActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home: {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app's task, so create a new
            // task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();//from www  . ja v  a 2  s  .c  o m
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.dabay6.libraries.androidshared.util.NavigationUtils.java

/**
 * Navigate back up the back stack./*  w  ww. j a v  a2 s  .c  om*/
 *
 * @param activity The current {@link Activity}.
 */
public static void navigateUp(final Activity activity) {
    // This is called when the Home (Up) button is pressed in the action bar. Create a simple intent that starts the
    // hierarchical parent activity and use NavUtils in the Support Package to ensure proper handling of Up.
    final Intent upIntent = NavUtils.getParentActivityIntent(activity);

    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        // This activity is not part of the application's task, so create a new task with a synthesized back stack.
        TaskStackBuilder.create(activity)
                // If there are ancestor activities, they should be added here.
                .addNextIntent(upIntent).startActivities();
        activity.finish();
    } else {
        // This activity is part of the application's task, so simply navigate up to the hierarchical parent
        // activity.
        NavUtils.navigateUpTo(activity, upIntent);
    }
}

From source file:com.oprisnik.semdroid.AnalysisResultsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {

            // add required extras to intent
            upIntent.putExtra(AnalysisResultsOverviewFragment.KEY_PACKAGE_NAME,
                    getIntent().getStringExtra(AnalysisResultsOverviewFragment.KEY_PACKAGE_NAME));

            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();/*  ww  w .  j av  a 2s .co m*/
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.google.walkway.AboutActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
        } else {//from w w w .j ava  2 s .c o m
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            NavUtils.navigateUpTo(this, upIntent);
        }

        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:uk.org.rivernile.android.utils.NavigationUtils.java

/**
 * Call this method when it is necessary to navigate 'up' from an Activity
 * that only has a single known entry point. The parent Activity that is
 * used is defined in the AndroidManifest.xml, as described in 
 * {@link android.support.v4.app.NavUtils}.
 * /*from   w ww . j ava  2 s. co m*/
 * @param activity The Activity on which 'up' was pressed.
 * @return true if the navigation operation succeeded, false if it didn't.
 * This may happen if activity is null, or the parent Activity was not
 * defined in AndroidManifest.xml.
 * @see android.support.v4.app.NavUtils
 */
public static boolean navigateUpOnActivityWithSingleEntryPoint(final Activity activity) {
    if (activity == null) {
        return false;
    }

    final Intent upIntent = NavUtils.getParentActivityIntent(activity);

    if (upIntent == null) {
        return false;
    }

    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntent(upIntent).startActivities();
        activity.finish();
    } else {
        NavUtils.navigateUpTo(activity, upIntent);
    }

    return true;
}

From source file:com.github.piasy.taskdemo.NotifyActivity.java

@Override
public void onBackPressed() {
    Intent upIntent = NavUtils.getParentActivityIntent(this);
    if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
        TaskStackBuilder.create(this).addNextIntent(upIntent).startActivities();
    } else {//from  w w  w.ja v  a  2 s.c  om
        NavUtils.navigateUpFromSameTask(this);
    }
}

From source file:com.bangz.shotrecorder.Prefs.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {

        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();/* w w  w  .  ja v  a2 s.  c  o m*/
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            NavUtils.navigateUpFromSameTask(this);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}