本文整理汇总了Java中android.support.v4.app.NavUtils.shouldUpRecreateTask方法的典型用法代码示例。如果您正苦于以下问题:Java NavUtils.shouldUpRecreateTask方法的具体用法?Java NavUtils.shouldUpRecreateTask怎么用?Java NavUtils.shouldUpRecreateTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.NavUtils
的用法示例。
在下文中一共展示了NavUtils.shouldUpRecreateTask方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@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);
}
示例2: navigateUpOrBack
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
/**
* This utility method handles Up navigation intents by searching for a parent activity and
* navigating there if defined. When using this for an activity make sure to define both the
* native parentActivity as well as the AppCompat one when supporting API levels less than 16.
* when the activity has a single parent activity. If the activity doesn't have a single parent
* activity then don't define one and this method will use back button functionality. If "Up"
* functionality is still desired for activities without parents then use
* {@code syntheticParentActivity} to define one dynamically.
*
* Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
* in Material Design guidelines.
*
* @param currentActivity Activity in use when navigate Up action occurred.
* @param syntheticParentActivity Parent activity to use when one is not already configured.
*/
public static void navigateUpOrBack(Activity currentActivity,
Class<? extends Activity> syntheticParentActivity) {
// Retrieve parent activity from AndroidManifest.
Intent intent = NavUtils.getParentActivityIntent(currentActivity);
// Synthesize the parent activity when a natural one doesn't exist.
if (intent == null && syntheticParentActivity != null) {
try {
intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
if (intent == null) {
// No parent defined in manifest. This indicates the activity may be used by
// in multiple flows throughout the app and doesn't have a strict parent. In
// this case the navigation up button should act in the same manner as the
// back button. This will result in users being forwarded back to other
// applications if currentActivity was invoked from another application.
currentActivity.onBackPressed();
} else {
if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
// Need to synthesize a backstack since currentActivity was probably invoked by a
// different app. The preserves the "Up" functionality within the app according to
// the activity hierarchy defined in AndroidManifest.xml via parentActivity
// attributes.
TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
builder.addNextIntentWithParentStack(intent);
builder.startActivities();
} else {
// Navigate normally to the manifest defined "Up" activity.
NavUtils.navigateUpTo(currentActivity, intent);
}
}
}
示例3: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
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)
.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;
} else if (item.getTitle().equals("Settings")) {
//startActivity(new Intent(this, Settings.class));
finish();
// overridePendingTransition(R.anim.hold, R.anim.push_out_to_left);
return true;
}
return super.onOptionsItemSelected(item);
}
示例4: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
示例5: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if ( null != upIntent ) {
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);
}
}
else {
onBackPressed();
}
return true;
}
return super.onOptionsItemSelected( item );
}
示例6: navigateUp
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
public static void navigateUp(Activity activity, Bundle extras) {
Intent upIntent = NavUtils.getParentActivityIntent(activity);
if (upIntent == null) {
com.hanyee.androidlib.utils.LogUtils.w("No parent found for activity, will just call finish(): "
+ activity.getClass().getName());
} else {
if (extras != null) {
upIntent.putExtras(extras);
}
if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
com.hanyee.androidlib.utils.LogUtils.i("Creating new task");
// 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(activity)
// 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.
com.hanyee.androidlib.utils.LogUtils.i("Using original task");
// According to http://stackoverflow.com/a/14792752/2420519
//NavUtils.navigateUpTo(activity, upIntent);
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(upIntent);
}
}
activity.finish();
}
示例7: navigateUp
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
private void navigateUp() {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
}
示例8: onOptionsHomeSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
protected final void onOptionsHomeSelected() {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (null == upIntent) {
finish();
} else {
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, upIntent);
}
}
}
示例9: supportShouldUpRecreateTask
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent) {
return NavUtils.shouldUpRecreateTask(this, targetIntent);
}
示例10: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (upIntent != null)
if (NavUtils.shouldUpRecreateTask(this, upIntent))
TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
else
NavUtils.navigateUpTo(this, upIntent);
return true;
case R.id.menu_usage:
optionUsage();
return true;
case R.id.menu_accounts:
optionAccounts();
return true;
case R.id.menu_applications:
optionApplications();
return true;
case R.id.menu_contacts:
if (item.getGroupId() != 0) {
optionContacts(item.getGroupId());
return true;
} else
return false;
case R.id.menu_whitelists:
optionWhitelists(null);
return true;
case R.id.menu_apply:
optionTemplate();
return true;
case R.id.menu_clear:
optionClear();
return true;
case R.id.menu_export:
optionExport();
return true;
case R.id.menu_import:
optionImport();
return true;
case R.id.menu_submit:
optionSubmit();
return true;
case R.id.menu_fetch:
optionFetch();
return true;
case R.id.menu_settings:
optionSettings();
return true;
case R.id.menu_dump:
optionDump();
return true;
case R.id.menu_legend:
optionLegend();
return true;
case R.id.menu_tutorial:
optionTutorial();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例11: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
UsageTask usageTask;
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (upIntent != null)
if (NavUtils.shouldUpRecreateTask(this, upIntent))
TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
else
NavUtils.navigateUpTo(this, upIntent);
return true;
case R.id.menu_usage_all:
mAll = !mAll;
if (mUsageAdapter != null)
mUsageAdapter.getFilter().filter(Boolean.toString(mAll));
return true;
case R.id.menu_refresh:
updateTitle();
usageTask = new UsageTask();
usageTask.executeOnExecutor(mExecutor, (Object) null);
return true;
case R.id.menu_clear:
PrivacyManager.deleteUsage(mUid);
usageTask = new UsageTask();
usageTask.executeOnExecutor(mExecutor, (Object) null);
return true;
case R.id.menu_whitelists:
if (Util.hasProLicense(this) == null) {
// Redirect to pro page
Util.viewUri(this, ActivityMain.cProUri);
} else {
WhitelistTask whitelistsTask = new WhitelistTask(mUid, null, this);
whitelistsTask.executeOnExecutor(mExecutor, (Object) null);
}
return true;
case R.id.menu_settings:
Intent intent = new Intent(this, ActivitySettings.class);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}