Java Code Examples for android.support.v4.app.NavUtils#navigateUpTo()

The following examples show how to use android.support.v4.app.NavUtils#navigateUpTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewDetailActivity.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpTo(this, new Intent(this, ViewListActivity.class));
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 2
Source File: DebatesActivity.java    From kaif-android with Apache License 2.0 6 votes vote down vote up
@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 {
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, upIntent);
      }
      return true;
    case R.id.action_open_link:
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setData(article.getPermaLink());
      intent.addCategory(Intent.CATEGORY_BROWSABLE);
      this.startActivity(intent);
      return true;
  }

  return super.onOptionsItemSelected(item);
}
 
Example 3
Source File: CardFlipActivity.java    From AndroidTrainingCode with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;

        case R.id.action_flip:
            flipCard();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 4
Source File: OrderDetailActivity.java    From Pharmacy-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpTo(this, new Intent(this, OrderListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 5
Source File: ClassifyActivity.java    From android-galaxyzoo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    // Handle presses on the action bar items
    final int id = item.getItemId();

    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        final Intent intent = new Intent(this, ListActivity.class);
        NavUtils.navigateUpTo(this, intent);
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 6
Source File: LayoutChangesActivity.java    From AndroidTrainingCode with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;

        case R.id.action_add_item:
            // Hide the "empty" view since there is now at least one item in the list.
            findViewById(android.R.id.empty).setVisibility(View.GONE);
            addItem();
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: ContentViewActivity.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.from(this)
                    .addParentStack(this)
                    .startActivities();
            finish();
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 8
Source File: MusicTrackListActivity.java    From PlayMusicExporter with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpTo(this, new Intent(this, MusicContainerListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: FeedActivity.java    From android-mvp-architecture with Apache License 2.0 6 votes vote down vote up
@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);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            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);
}
 
Example 10
Source File: ActionbarActivity.java    From ui with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		// Navigate "up" the demo structure to the launchpad activity.
		// See http://developer.android.com/design/patterns/navigation.html for more.
		NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
		return true;

	case R.id.action_previous:
		// Go to the previous step in the wizard. If there is no previous step,
		// setCurrentItem will do nothing.
		viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
		return true;

	case R.id.action_next:
		// Advance to the next step in the wizard. If there is no next step, setCurrentItem
		// will do nothing.
		viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
		return true;
	}

	return super.onOptionsItemSelected(item);
}
 
Example 11
Source File: RegistActivity.java    From weixin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home://返回上一菜单页
		AppToast.getToast().show("返回上一页");
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
			TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
		} else {
			upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			NavUtils.navigateUpTo(this, upIntent);
		}
		break;

	default:
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 12
Source File: ChatActivity.java    From weixin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home://返回上一菜单页
		AppToast.getToast().show("返回上一页");
		Intent upIntent = NavUtils.getParentActivityIntent(this);
		if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
			TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
		} else {
			upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			NavUtils.navigateUpTo(this, upIntent);
		}
		break;
	case R.id.menu_chat_chatInfo:
		AppToast.getToast().show(R.string.text_menu_chatInfo);
		break;
	default:
		break;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 13
Source File: ZoomActivity.java    From AndroidTrainingCode with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://developer.android.com/design/patterns/navigation.html for more.
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 14
Source File: FragMenuActivity.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {

	case android.R.id.home:
		Intent upIntent = new Intent(this, MainActivity.class);
		// This ID represents the Home or Up button. In the case of this
		// activity, the Up button is shown. Use NavUtils to allow users
		// to navigate up one level in the application structure. For
		// more details, see the Navigation pattern on Android Design:
		//
		// http://developer.android.com/design/patterns/navigation.html#up-vs-back
		//
		NavUtils.navigateUpTo(this,	upIntent);
		return true;
	case R.id.frag1:
		if (!isfrag1) {
			getSupportFragmentManager().beginTransaction()
			.replace(R.id.text_container, one).commit();
			isfrag1 = true;
			invalidateOptionsMenu();
		}
		return true;
	case R.id.frag2:
		if (isfrag1) {
			getSupportFragmentManager().beginTransaction()
			.replace(R.id.text_container, two).commit();
			isfrag1 = false;
			invalidateOptionsMenu();
		}
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 15
Source File: AnimationDetailActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	int id = item.getItemId();
	if (id == android.R.id.home) {
		NavUtils.navigateUpTo(this, new Intent(this,
				EasyAnimationListActivity.class));
		return true;
	}
	return super.onOptionsItemSelected(item);
}
 
Example 16
Source File: DetailActivity.java    From masterdetail-j2objc-swift with Apache License 2.0 5 votes vote down vote up
@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();
        } 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);
}
 
Example 17
Source File: GroupViewActivity.java    From smartcard-reader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent i = NavUtils.getParentActivityIntent(this);
            NavUtils.navigateUpTo(this, i);
            return true;

        case R.id.menu_edit_group:
            editGroup();
            return true;

        case R.id.menu_copy_group:
            copyGroup();
            return true;

        case R.id.menu_delete_group:
            showDialog(DIALOG_CONFIRM_DELETE);
            return true;

        case R.id.menu_rename_group:
            renameGroup();
            return true;

        case R.id.menu_select_group:
            selectGroup();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 18
Source File: MarkActivity.java    From Jreader with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onClick (View view) {
    Intent upIntent = NavUtils.getParentActivityIntent(this);
    if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent)
                .startActivities();
    } else {
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        NavUtils.navigateUpTo(this, upIntent);
    }
    finish();

}
 
Example 19
Source File: SnippetDetailActivity.java    From android-java-snippets-sample with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        NavUtils.navigateUpTo(this, new Intent(this, SnippetListActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 20
Source File: ExampleViewerActivity.java    From android-galaxyzoo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    // Handle presses on the action bar items
    final int id = item.getItemId();

    if (id == android.R.id.home) {
        //The base class just uses NavUtils.navigateUpFromSameTask() but we want to make sure
        //that the parent activity will be resumed instead of restarted,
        //to make sure we go back to the correct help for the correct question,
        //so we use FLAG_ACTIVITY_CLEAR_TOP.
        //Alternatively, we could just mark QuestionHelpActivity as
        //android:launchMode="singleTop" in the AndroidManifest.xml but it seems reasonable to
        //use QuestionHelpActivity from other places one day.

        //We can use this instead of more complex code, checking NavUtils.shouldUpRecreateTask(),
        //because we know that our activities will never be opened from another app.
        //See http://developer.android.com/training/implementing-navigation/ancestral.html.
        final Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (upIntent == null) {
            return false;
        }
        upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        NavUtils.navigateUpTo(this, upIntent);
        return true;
    }

    return super.onOptionsItemSelected(item);
}