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

The following examples show how to use android.support.v4.app.NavUtils#shouldUpRecreateTask() . 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: 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 2
Source File: ArticleCollectionActivity.java    From aard2-android with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example 3
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 4
Source File: LoginActivity.java    From v2ex-daily-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;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 5
Source File: UserActivity.java    From v2ex-daily-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;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 6
Source File: TopicActivity.java    From v2ex-daily-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;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 7
Source File: FilterEventACTIVITY.java    From ALLGO 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 = 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);
}
 
Example 8
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 9
Source File: WebActivity.java    From Small with Apache License 2.0 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 (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);
}
 
Example 10
Source File: SettingsActivity.java    From android 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) || 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);
}
 
Example 11
Source File: SettingsActivity.java    From Readily with MIT License 6 votes vote down vote up
@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);
}
 
Example 12
Source File: FeedActivity.java    From android-mvp-interactor-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 13
Source File: DetailFragment.java    From io2015-codelabs 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:
            // 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);
}
 
Example 14
Source File: DetailFragment.java    From io2015-codelabs 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:
            // 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);
}
 
Example 15
Source File: NewsFeedActivity.java    From kaif-android 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 = 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);
}
 
Example 16
Source File: AbstractBarterLiActivity.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }

}
 
Example 17
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 18
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 19
Source File: UserDetailedInfoActivity.java    From weixin 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://返回上一菜单页
		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);
}
 
Example 20
Source File: BaseActivity.java    From glimmr 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:
            /* 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);
}