本文整理汇总了Java中android.support.v4.app.NavUtils.navigateUpTo方法的典型用法代码示例。如果您正苦于以下问题:Java NavUtils.navigateUpTo方法的具体用法?Java NavUtils.navigateUpTo怎么用?Java NavUtils.navigateUpTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.app.NavUtils
的用法示例。
在下文中一共展示了NavUtils.navigateUpTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@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, SimpleListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
示例3: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@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, ItemListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
示例4: 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);
}
}
}
示例5: 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);
}
示例6: 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);
}
示例7: showDiaryView
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public void showDiaryView() {
getActivity().setResult(Activity.RESULT_OK);
if(getActivity().getIntent().getBooleanExtra(FROM_MAIN_ACTIVITY, false)) {
getActivity().finish();
}
else {
// Navigate up to MainActivity with a new intent to view the diary tab
Intent intent = NavUtils.getParentActivityIntent(getActivity());
intent.putExtra(MainActivity.REQUESTED_TAB_NAME, getResources().getString(R.string.diary_tab_name));
NavUtils.navigateUpTo(getActivity(), intent);
}
}
示例8: 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 );
}
示例9: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例10: 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);
}
}
示例11: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
savedata();
Intent intent = NavUtils.getParentActivityIntent(this).putExtra("delay", 5);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, intent);
return true;
}
return super.onOptionsItemSelected(item);
}
示例12: 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);
}
}
}
示例13: onOptionsItemSelected
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent up = NavUtils.getParentActivityIntent(this);
up.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
NavUtils.navigateUpTo(this, up);
return true;
}
return super.onOptionsItemSelected(item);
}
示例14: 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);
}
}
示例15: supportNavigateUpTo
import android.support.v4.app.NavUtils; //导入方法依赖的package包/类
public void supportNavigateUpTo(@NonNull Intent upIntent) {
NavUtils.navigateUpTo(this, upIntent);
}