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:masterdetail.android.DetailActivity.java

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

        final EditText title = (EditText) findViewById(R.id.masterdetail_detail_title);
        final EditText words = (EditText) findViewById(R.id.masterdetail_detail_words);

        viewModel.save(title.getText().toString(), words.getText().toString());

        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 ww.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 true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.marijaradisavljevic.bla.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, MainActivityMarijs.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//w ww  .ja v  a  2s.co  m
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.app.v1.iresto.DemoSwipeTab2Activity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, DemoSwipeTabActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//from  www .  j ava 2 s . c om
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.handsfree.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, LaunchTutorial.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//from w w w  .j  a v a  2s  .  c  om
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.agilemessage.ameffectivenavigation.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();/*from w  w w  . j  av a2 s .  co  m*/
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.hfmb.hfmbapp.CollectionDemoActivity.java

@SuppressWarnings("deprecation")
@Override/*from w  w w  . j a v a 2s.  c  o  m*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, MainActivity_app.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:cn.androidy.androiddevelopmentpatterns.ui.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, NaviMainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();/*from  w ww.jav a2  s .c  om*/
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:me.crossle.nav.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();/*from   w  w w  .jav  a2s.  c  o m*/
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.lightcontrol.CollectionDemoActivity.java

@SuppressWarnings("deprecation")
@Override/* ww  w  .  ja va 2s .co m*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.androidtitlan.retrocompatibilitytutorial.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // 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.
        Intent upIntent = new Intent(this, InitialActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//  w ww .j a  v a  2s  .c  om
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}