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

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

Introduction

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

Prototype

public static Intent getParentActivityIntent(Activity sourceActivity) 

Source Link

Document

Obtain an Intent that will launch Intent#ACTION_MAIN with an explicit target activity specified by sourceActivity's #PARENT_ACTIVITY <meta-data> element in the application's manifest.

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 w  ww .j  av  a 2  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);//from w w w.  j  a 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.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 w  w  w  .  j a  v a  2 s  .co  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./*www. ja va2s  .c o  m*/
 *
 * @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:org.iteventviewer.app.BaseActivity.java

protected Intent upIntent() {
    return NavUtils.getParentActivityIntent(this);
}

From source file:com.blipsqueak.app.BaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        NavUtils.navigateUpTo(this, upIntent);
        overridePendingTransition(R.anim.exit_in, R.anim.exit_out);
        return true;
    }//from   www  .  jav a 2 s.co  m
    return super.onOptionsItemSelected(item);
}

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();/*from   www  . jav  a 2  s . c om*/
        } 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: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 a  v  a2  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.example.joeroger.sampleplaces.activity.LicenseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
    case android.R.id.home:
        Intent intent = NavUtils.getParentActivityIntent(this);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, intent);
        return true;

    default:/*from   w  ww.j  a  v  a 2 s  .co  m*/
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.example.joeroger.homework2.activity.OpenSourceLicenseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == android.R.id.home) {
        Intent parentActivityIntent = NavUtils.getParentActivityIntent(this);
        parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        NavUtils.navigateUpTo(this, parentActivityIntent);
        return true;
    }/*from w  ww  . j a  v  a  2 s . co  m*/

    return super.onOptionsItemSelected(item);
}