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:com.meetingninja.csse.user.RegisterActivity.java

@Override
public void onBackPressed() {
    Intent upIntent = new Intent(this, LoginActivity.class);
    if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
        // This activity is NOT part of this app's task, so create a new
        // task/*from w  w  w .ja  v  a 2s . c  om*/
        // when navigating up, with a synthesized back stack.
        TaskStackBuilder.create(this)
                // Add all of this activity's parents to the back stack
                .addNextIntent(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.
        NavUtils.navigateUpTo(this, upIntent);
    }
}

From source file:org.ounl.lifelonglearninghub.nfcecology.db.CreateGoalActivity.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./*from  w ww  .  ja v  a 2s .  c  om*/
        // 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.bestjoy.app.haierwarrantycard.ui.SettingsPreferenceActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent == null) {
            // If we has configurated parent Activity in AndroidManifest.xml, we just finish current Activity.
            finish();//w  ww  . j  a  v  a2  s  .c o m
            return true;
        }
        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();
        } 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:ca.uqac.florentinth.speakerauthentication.CreateActivity.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  ww  .j  a v  a2s .  c om
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.silentcircle.contacts.activities.ScContactDetailActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
        // This activity must not be shown. We have to select the contact in the
        // PeopleActivity instead ==> Create a forward intent and finish
        final Intent originalIntent = getIntent();
        Intent intent = new Intent();
        intent.setAction(originalIntent.getAction());
        intent.setDataAndType(originalIntent.getData(), originalIntent.getType());

        // If we are launched from the outside, we should create a new task, because the user
        // can freely navigate the app (this is different from phones, where only the UP button
        // kicks the user into the full app)
        if (NavUtils.shouldUpRecreateTask(this, intent)) {
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                    | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        } else {//from  w ww.j a va  2  s.c om
            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }

        intent.setClass(this, ScContactsMainActivity.class);
        startActivity(intent);
        finish();
        return;
    }

    setContentView(R.layout.contact_detail_activity);

    mContactDetailLayoutController = new ContactDetailLayoutController(this, savedState,
            getSupportFragmentManager(), null, findViewById(R.id.contact_detail_container),
            mContactDetailFragmentListener);

    // We want the UP affordance but no app icon.
    // Setting HOME_AS_UP, SHOW_TITLE and clearing SHOW_HOME does the trick.
    ActionBar actionBar = this.getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE,
                ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle("");
    }

    Log.i(TAG, getIntent().getData().toString());
}

From source file:com.enadein.carlogbook.core.BaseActivity.java

@Override
public boolean onOptionsItemSelected(android.view.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 {//w  ww. j  a v a2 s . c om
            //upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    }

    return super.onOptionsItemSelected(item);
}

From source file:pt.ubi.di.pdm.swipe.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int index = mViewPager.getCurrentItem();
    Fragment fragment = mDemoCollectionPagerAdapter.getFragment(index);
    TextView title = ((TextView) fragment.getView().findViewById(R.id.details_entry_title));
    TextView title_textView = ((TextView) fragment.getView().findViewById(R.id.details_file_text));
    EditText textview = ((EditText) fragment.getView().findViewById(R.id.details_entry_text));
    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  ww  .j a v  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;
    case R.id.create_new_file:
        Log.i("Menu", "create_new");
        Intent iActivity = new Intent(this, CreateFile.class);//
        iActivity.putExtra("string1", "if you are able to do this, you are FABULOUS");
        startActivity(iActivity);
        FILES_IN_DIR = directoryListofFiles(this);
        return true;
    case R.id.open:
        if (fragment == null)
            Log.i("Fragment", "fragment NULL");
        else {
            if (title != null && title_textView != null && textview != null) {
                String words = ReadBtn(this, FILES_IN_DIR.elementAt(index));
                //title_textView.setText(title_textView.getText().toString().replace(" (sem pontuao)", ""));
                if (title_textView.getText().toString().contains("sem pontuao")) {
                    String[] aux_title = title_textView.getText().toString().split("\\(sem pontuao");
                    title_textView.setText(aux_title[0]);
                }
                if (title_textView.getText().toString().contains("sem vogais")) {
                    String[] aux_title = title_textView.getText().toString().split("\\(sem vogais");
                    title_textView.setText(aux_title[0]);
                }
                textview.setText(words);
                Log.i("TAG", "Carregou ficheiro "
                        + directoryListofFiles(this).elementAt(mViewPager.getCurrentItem()));
            }
        }
        Log.i("Menu", "open");
        return true;

    case R.id.delete_file:
        if (fragment == null)
            Log.i("Fragment", "fragment NULL");
        else {
            if (textview != null) {
                File file = new File(getFilesDir(), FILES_IN_DIR.get(index));
                boolean deleted = file.delete();
                Toast.makeText(getApplicationContext(), "Ficheiro Eliminado", Toast.LENGTH_LONG).show();
                Log.i("Menu", "delete_file");
            }
        }

        return true;
    case R.id.save:
        if (fragment == null)
            Log.i("Fragment", "fragment NULL");
        else {
            if (textview != null) {
                WriteBtn(this, directoryListofFiles(this).elementAt(index), textview.getText().toString());
            }
        }
        return true;
    case R.id.remove_punctuation_details:
        if (fragment == null)
            Log.i("Fragment", "fragment NULL");
        else {
            if (textview != null) {
                String words = textview.getText().toString().replace(PUNCTUATION, "");

                String removed_chars = removedItensFromText(textview, PUNCTUATION).toString();
                Log.i("OLA", removedItensFromText(textview, PUNCTUATION).toString());
                String text = UNDESIRABLES_PUNCTUATION.matcher(words).replaceAll("");
                if (textview.getText().toString().equals(text))
                    Log.i("TAG", "Nao removeu");
                else {
                    if (!title_textView.getText().toString().contains("sem pontuao"))
                        title_textView.setText(title_textView.getText() + " (sem pontuao "
                                + removed_chars.replaceAll("\\[(.*?)\\]", "$1").replace(",", "  ") + " )");
                    textview.setText(text);
                }
                Toast.makeText(this, "Removeu Pontuao!", Toast.LENGTH_SHORT).show();
                Log.i("TAG", UNDESIRABLES_PUNCTUATION.matcher(words).replaceAll(""));
            }
        }
        return true;
    case R.id.remove_vowels_details:
        if (fragment == null)
            Log.i("Fragment", "fragment NULL");
        else {
            if (textview != null) {
                // This should be fast enough for most purposes, assuming the JVM's
                // regex engine optimizes the character class lookup.
                // http://stackoverflow.com/questions/17531362/efficiently-removing-specific-characters-some-punctuation-from-strings-in-java
                String words = textview.getText().toString().replace(VOWELS, "");
                String removed_chars = removedItensFromText(textview, VOWELS).toString();

                String text = UNDESIRABLES_VOWELS.matcher(words).replaceAll("");
                if (textview.getText().toString().equals(text))
                    Log.i("TAG", "Nao removeu");
                else {
                    if (!title_textView.getText().toString().contains("sem vogais"))
                        title_textView.setText(title_textView.getText() + " (sem vogais "
                                + removed_chars.replaceAll("\\[(.*?)\\]", "$1").replace(",", "  ") + " )");
                    textview.setText(text);
                }
                Toast.makeText(this, "Removeu Vogais!", Toast.LENGTH_SHORT).show();
                Log.i("TAG", UNDESIRABLES_VOWELS.matcher(words).replaceAll(""));
            }
        }
        return true;

    }
    return super.onOptionsItemSelected(item);
}

From source file:net.wequick.small.webkit.WebActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent == null) {
            finish();/*from  ww w  .ja v a  2 s . c om*/
        } else {
            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();
            } 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:org.sudowars.Controller.Local.Activity.Manual.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent upIntent = new Intent(this, MainMenu.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();
            finish();/*  www.j  a v a  2 s .  c o m*/
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:in.rab.ordboken.Ordboken.java

public boolean onOptionsItemSelected(Activity activity, MenuItem item) {
    if (item.getItemId() == R.id.menu_logout) {
        updateCreds("", "");
        mNeClient.logout();/*from ww w  .j  av a 2 s .  c o  m*/

        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putBoolean("loggedIn", false);
        ed.putString("username", "");
        ed.putString("password", "");
        ed.commit();

        Intent intent = new Intent(mContext, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);

        activity.finish();

        return true;
    } else if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(activity);
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities();
        } else {
            NavUtils.navigateUpFromSameTask(activity);
        }
        return true;
    }

    return false;
}