下面列出了android.support.v4.app.NavUtils#shouldUpRecreateTask ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@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);
startActivity(upIntent);
finish();
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
// This is probably because we opened settings from the notification.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (upIntent == null) {
finish();
} 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);
}
@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);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = new Intent(this, HomeACTIVITY.class);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.from(this)
//如果这里有很多原始的Activity,它们应该被添加在这里
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@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;
default:
return super.onOptionsItemSelected(item);
}
}
@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;
default:
return super.onOptionsItemSelected(item);
}
}
@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;
default:
return super.onOptionsItemSelected(item);
}
}
@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);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = Intent.makeMainActivity(new ComponentName(this, MainActivity.class));
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.create(this)
.addNextIntent(upIntent).startActivities();
finish();
} else {
// This activity is part of the application's task, so simply
// navigate up to the hierarchical parent activity.
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(upIntent);
finish();
}
return true;
}
return super.onOptionsItemSelected(item);
}
@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);
}
@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();
}
/**
* Moves up in the hierarchy using the Support meta data specified in manifest
*/
private void doUpNavigation() {
final Intent upIntent = NavUtils.getParentActivityIntent(this);
if (upIntent == null) {
NavUtils.navigateUpFromSameTask(this);
} 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);
}
}
}
@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;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Some small additions to handle "up" navigation correctly
Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Check if up activity needs to be created (usually when
// detail screen is opened from a notification or from the
// Wearable app
if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
|| getActivity().isTaskRoot()) {
// Synthesize parent stack
TaskStackBuilder.create(getActivity())
.addNextIntentWithParentStack(upIntent)
.startActivities();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// On Lollipop+ we finish so to run the nice animation
getActivity().finishAfterTransition();
return true;
}
// Otherwise let the system handle navigating "up"
return false;
case R.id.map:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(Constants.MAPS_INTENT_URI +
Uri.encode(mAttraction.name + ", " + mAttraction.city)));
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Some small additions to handle "up" navigation correctly
Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Check if up activity needs to be created (usually when
// detail screen is opened from a notification or from the
// Wearable app
if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
|| getActivity().isTaskRoot()) {
// Synthesize parent stack
TaskStackBuilder.create(getActivity())
.addNextIntentWithParentStack(upIntent)
.startActivities();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// On Lollipop+ we finish so to run the nice animation
getActivity().finishAfterTransition();
return true;
}
// Otherwise let the system handle navigating "up"
return false;
case R.id.map:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(Constants.MAPS_INTENT_URI +
Uri.encode(mAttraction.name + ", " + mAttraction.city)));
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@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_userDetailedInfo_pencil:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_pencil);
break;
case R.id.menu_userDetailedInfo_stars:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_stars);
break;
case R.id.menu_userDetailedInfo_jurisdiction:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_jurisdiction);
break;
case R.id.menu_userDetailedInfo_forward:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_forward);
break;
case R.id.menu_userDetailedInfo_blacklist:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_blacklist);
break;
case R.id.menu_userDetailedInfo_delete:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_delete);
break;
case Menu.FIRST + 1:
AppToast.getToast().show(R.string.text_menu_userDetailedInfo_addTodesktop);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
@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. http://goo.gl/lJxjA */
Intent upIntent = new Intent(this, MainActivity.class);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.from(this)
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
case R.id.menu_preferences:
Intent preferencesActivity = new Intent(getBaseContext(),
SettingsActivity.class);
startActivity(preferencesActivity);
return true;
case R.id.menu_upload:
if (Constants.PRO_VERSION) {
Intent localPhotosActivity = new Intent(getBaseContext(),
LocalPhotosActivity.class);
startActivity(localPhotosActivity);
} else {
BuyProDialog.show(this);
}
return true;
case R.id.menu_about:
new AboutDialogFragment().show(getSupportFragmentManager(), "AboutDialogFragment");
return true;
}
return super.onOptionsItemSelected(item);
}